2

I have this figure generated by the following code. It is overflowing. How do I make it fit the page width?

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}

\usepackage{tabularray} % https://www.latex-tables.com/# \usepackage{amsmath} \usepackage{float} \usepackage{subfig} \usepackage{graphicx} \usepackage{tikz}% loads graphicx \usetikzlibrary{calc} \usetikzlibrary{chains}

\begin{document}

\begin{figure} \begin{tikzpicture}[start chain=g going right,node distance=1mm, nodes={inner sep=0,on chain}] \node[anchor=south west] (image) at (0,0) {\includegraphics[width=0.2\textwidth,trim={0 50 0 0},clip]{example-image-a}}; \node {\includegraphics[width=0.2\textwidth]{example-image-a}}; \node {\includegraphics[width=0.2\textwidth]{example-image-a}}; \node {\includegraphics[width=0.2\textwidth]{example-image-a}}; \node {\includegraphics[width=0.2\textwidth]{example-image-a}}; \node {\includegraphics[width=0.2\textwidth]{example-image-a}}; \draw (g-begin.north west|-g-end.north)+(0,1mm) -- ([xshift=-5cm,yshift=1mm]g-end.north east); \draw (g-begin.north west|-g-end.north)+(8cm,0mm) -- ([xshift=0,yshift=0mm]g-end.north east); \node[] at (3cm,2cm) {Reconstruct}; \node[] at (8cm,2cm) {Forecast}; \end{tikzpicture} \caption{Given the historical human and object motion} \label{fig:intro} \end{figure}

\end{document}

I included the textwidth variable but it does not work.

\begin{figure}[width=\textwidth]
...
...
...
\end{figure}
Kong
  • 2,313

1 Answers1

6

Unless there is more going on, I think a simple table should be enough to solve your problem

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{graphicx}

\begin{document} \begin{figure}[tbh] \setlength{\tabcolsep}{2pt} \centering \begin{tabularx}{\textwidth}{@{}*6{X}@{}} \multicolumn{3}{c}{Reconstruct} & \multicolumn{3}{c}{Forecast} \ \midrule \includegraphics[width=\linewidth]{example-image-a} & \includegraphics[width=\linewidth]{example-image-a} & \includegraphics[width=\linewidth]{example-image-a} & \includegraphics[width=\linewidth]{example-image-a} & \includegraphics[width=\linewidth]{example-image-a} & \includegraphics[width=\linewidth]{example-image-a} \end{tabularx} \caption{Given the historical human and object motion}\label{fig:intro} \end{figure} \end{document}

enter image description here

Celdor
  • 9,058
  • wow that is significantly easier to read ! Just one question, how can I "cut" the midrule in the middle as it should not be a single continuous line. In the code I have above I had to manually search for the right value through trial and error. The custom midrule length only lets me have 1 midrule per line https://tex.stackexchange.com/questions/482214/custom-midrule-length – Kong Apr 20 '23 at 16:53
  • 2
    Np, in the code, change \midrule to \cmidrule[\lightrulewidth](r{2pt}){1-3} \cmidrule[\lightrulewidth](l{2pt}){4-6}. The part [...] sets thickness of the rule and \lightrulewidth is equivalent to \midrule. You could also try \heavyrulewidth or \cmidrulewidth (default) or just use numerics such as 1.2pt. More info in documentation. – Celdor Apr 20 '23 at 17:04
  • thank you so much ! – Kong Apr 20 '23 at 18:02