2

I am trying to fix a 4 by 3 set of graphs, with caption, on a .tex file. The result I want to achieve is the following:

enter image description here

(this was done in Word. Yes, that's lame, I know.)

The code for each small graph is the following:

\begin{tikzpicture}
\draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
\end{tikzpicture}

I've tried a bunch of subfigure/minipage options but the result I am getting is far from ideal (below)

\begin{minipage}[b]{0.3\linewidth}
\centering
\begin{tikzpicture}
\draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
\end{tikzpicture}
\end{minipage}%%
\begin{minipage}[b]{0.3\linewidth}
    \centering
    \begin{tikzpicture}
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture}
\end{minipage} 
\begin{minipage}[b]{0.3\linewidth}
    \centering
    \begin{tikzpicture}
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture}
\end{minipage}%%

enter image description here

EDIT

I've fixed the positioning, but not (yet) the caption. Can someone give me a hint?

\newpage
\begin{figure}[H]
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture}
\end{figure}

\begin{figure}[H]
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture}
\end{figure}

\begin{figure}[H]
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture}
\end{figure}

\begin{figure}[H]
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture} \hfill
    \begin{tikzpicture}[scale=0.36]
    \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
    \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
    \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
    \end{tikzpicture}
\end{figure}

Result:

enter image description here

  • Use minipage like you did but add a \hfill between them. To start a new row just add a linebreak. You can add a caption with captionof{figure}{your caption} from the caption package or from KOMA-Script if you're using it – faltfe Aug 8 '18 at 13:05
  • you don't need subfigure or minipages or anything, just put the tikzpicture one after the other and latex will arrange them into lines, just as it does any other paragraph – David Carlisle Aug 8 '18 at 13:07
  • @faltfe you mean like this? \begin{minipage}[b]{0.32\linewidth} \centering \begin{tikzpicture} \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9); \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$}; \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};... \end{tikzpicture} \end{minipage}\hfill \begin{minipage}[b]{0.32\linewidth} \centering ... (didn't work) – bru1987 Aug 8 '18 at 13:10
  • 1
    The problem is that tikzpicture works with actual paper dimensions (default is cm), so you explicitly told it to make a picture larger than \textwidth/3. You probably want \resizebox... – Phelype Oleinik Aug 8 '18 at 13:13
  • 2
    please do not edit solutions in to the question it makes it very hard to answer. Also you have not provided an example document that makes it easy for people to see the problem or test answers. – David Carlisle Aug 8 '18 at 13:30
1

little late ... but it may help someone :-)

i would draw your diagrams with the pgfplots package. using it is simple to define size of diagrams in dependency from \textwidth and preserve drawn functions' domains independent from diagram size. it also enable adding diagrams titles with option title:

\documentclass{article}
\usepackage[margin=30mm]{geometry}  % define page layout

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

    \begin{document}
    \begin{figure}[htbp]
    \pgfplotsset{width=0.3\linewidth,  % digrams' size
                 scale only axis,
                 axis lines = middle,
                 grid,
                 grid style = {very thin, densely dashed},
                 xmin=-4.8, xmax=4.8, xtick={-4,-3,...,4}, xticklabels={},
                 ymin=-4.8, ymax=4.8, ytick={-4,-3,...,4}, yticklabels={},
                 xlabel=$x$, ylabel=$y$,
                 xlabel style = {anchor=west,  font=\footnotesize},
                 ylabel style = {anchor=south, font=\footnotesize},
                 title style = {yshift=1mm},
                 %
                 every axis plot post/.append style={very thick, color=blue!50, smooth},
                }
\begin{tikzpicture}
    \begin{axis}[title={$y=x$}]
\addplot [domain=-4:4] {x};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^2$}]
\addplot [domain=-4:4] {x^2};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^3$}]
\addplot [domain=-4:4] {x^3};
    \end{axis}
\end{tikzpicture}

\medskip
\begin{tikzpicture}
    \begin{axis}[title={$y=x$}]
\addplot [domain=-4:4] {x};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^2$}]
\addplot [domain=-4:4] {x^2};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^3$}]
\addplot [domain=-4:4] {x^3};
    \end{axis}
\end{tikzpicture}

\medskip
\begin{tikzpicture}
    \begin{axis}[title={$y=x$}]
\addplot [domain=-4:4] {x};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^2$}]
\addplot [domain=-4:4] {x^2};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^3$}]
\addplot [domain=-4:4] {x^3};
    \end{axis}
\end{tikzpicture}

\medskip
\begin{tikzpicture}
    \begin{axis}[title={$y=x$}]
\addplot [domain=-4:4] {x};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^2$}]
\addplot [domain=-4:4] {x^2};
    \end{axis}
\end{tikzpicture} \hfill
\begin{tikzpicture}
    \begin{axis}[title={$y=x^3$}]
\addplot [domain=-4:4] {x^3};
    \end{axis}
\end{tikzpicture}
    \caption{Twelve diagrams}
\label{fig:twelve}
    \end{figure}
\end{document}

enter image description here

(red lines indicate page layout)

0

does it work? Just replace the example image with your tikz code

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{mwe}

\begin{document}
\begin{figure*}
\centering
 %%%%%%%%%start of 1st row%%%%%%%%%%%%%%
 \begin{subfigure}[b]{0.3\textwidth}
        \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im1}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.3\textwidth}  
        \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im2}
    \end{subfigure}
\hfill
    \begin{subfigure}[b]{0.3\textwidth}  
        \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im3}
    \end{subfigure}
%%%%%%%%%%%%%End of 1st row %%%%%%%%%%%%%%%%%%%%%%%%      
    \vskip\baselineskip
    %%%%%%%%%%%%start of 2nd row%%%%%%%%%%%%%%%
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im4}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.3\textwidth}  
        \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im5}
    \end{subfigure}
\hfill
    \begin{subfigure}[b]{0.3\textwidth}  
         \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im6}
    \end{subfigure}
%%%%%%%%%%%%% End of 2nd row %%%%%%%%%%%%%%%%%%%%%    
    \vskip\baselineskip
    %%%%%%%%%%%%start of 3rd row%%%%%%%%%%%%%%%
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im7}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.3\textwidth}  
        \centering
\includegraphics[width=\textwidth]{example.eps}
\caption{your caption}
\label{im8}
    \end{subfigure}
\hfill
    \begin{subfigure}[b]{0.3\textwidth}  
        \centering
\includegraphics[width=\textwidth]{example.eps}
 \caption{your caption}
 \label{im9}
    \end{subfigure}
 %%%%%%%%%%%%%End of 3rd row %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
    \vskip\baselineskip
    %%%%%%%%%%%%start of 4th row%%%%%%%%%%%%%%%
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
  \includegraphics[width=\textwidth]{example.eps}
 \caption{your caption}
 \label{im10}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.3\textwidth}  
        \centering
 \includegraphics[width=\textwidth]{example.eps}
 \caption{your caption}
 \label{im11}
    \end{subfigure}
  \hfill
    \begin{subfigure}[b]{0.3\textwidth}  
        \centering
 \includegraphics[width=\textwidth]{example.eps}
 \caption{your caption}
 \label{im12}
    \end{subfigure}
  %%%%%%%%%%%%%End of 4th row %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
 \end{figure*}
 \end{document}
0

Using the hint from @PhelypeOleinik that one need resizebox the following will do the basic grid layout.

\documentclass{article}
\usepackage{graphicx, tikz, caption}

\begin{document}
    \begin{minipage}{.3\linewidth}
        \resizebox{\linewidth}{!}{%
            \begin{tikzpicture}
            \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
            \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
            \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
            \end{tikzpicture}
        }
    \captionof{figure}{test}
    \end{minipage}
    \hfill
    \begin{minipage}{.3\linewidth}
        \resizebox{\linewidth}{!}{%
            \begin{tikzpicture}
            \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
            \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
            \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
            \end{tikzpicture}
        }
        \captionof{figure}{test}
    \end{minipage}
    \hfill
    \begin{minipage}{.3\linewidth}
        \resizebox{\linewidth}{!}{%
            \begin{tikzpicture}
            \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
            \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
            \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
            \end{tikzpicture}
        }
        \captionof{figure}{test}
    \end{minipage}

    \begin{minipage}{.3\linewidth}
        \resizebox{\linewidth}{!}{%
            \begin{tikzpicture}
            \draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
            \draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
            \draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};...
            \end{tikzpicture}
        }
        \captionof{figure}{test}
    \end{minipage}
    \dots
\end{document}

Each minipage is using 30 % of the available linewidth. The gap between the minipages get automatically filled by \hfill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.