2

Today I discovered the existence of this wonderful package called "standalone". I really love it because I have a lot of pictures in Tikz code and some of them have a very long code and it's very difficult to handle and annoying when I'm trying to concentrate on the text rather than on pictures. So here is my problem, I have some small pictures that I want to align in the same row (sometimes 2, 3 or 4 of them in the same row). Let's suppose that I have these stand alone pictures:

Picture1.tex:

    \documentclass{standalone}
    \usepackage{pgf,tikz}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    \begin{document}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \draw [domain=0.08:3.92] plot(\x,{(--1.04--0.32*\x)/1.96});
    \draw (3.6,0.98) node[anchor=north west] {$l_a$};
    \end{tikzpicture}
    \end{document}

Picture2.tex:

    \documentclass{standalone}
    \usepackage{pgf,tikz}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    \begin{document}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \draw [domain=0.08:3.92] plot(\x,{(--1.04--0.32*\x)/1.96});
    \draw (3.6,0.98) node[anchor=north west] {$l_b$};
    \end{tikzpicture}
    \end{document}

Within the body of my main Tex file:

%... 
impute(Picture1.tex)
impute(Picture2.tex)
%    

I want my pictures look like this: enter image description here

Also I wanted that my pictures have a general description below them. My first try was by using "figure" environment (\begin{figure}.../end{figure}) but the pictures are put in a different position rather than just after a given line of text, I don't want that the picture appears anywhere else like at the top of the page or something. Thank you so much for your help and so sorry if my question is so naive but I'm just starting to learn these things.

3

As said by Chris in comments, you can use minipages. To have caption and not to allow floating, you can avoid figure environment and use \captionof macro from either caption or capt-of packages.

\documentclass[a4paper,11pt]{article}
\usepackage{standalone}
\usepackage[singlelinecheck=off,hang]{caption}     %% provides \captionof command. capt-of package does this too.
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}

\usepackage{filecontents}

\begin{filecontents*}{picture1.tex}
    \documentclass{standalone}
    \usepackage{pgf,tikz}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    \begin{document}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \draw [domain=0.08:3.92] plot(\x,{(--1.04--0.32*\x)/1.96});
    \draw (3.6,0.98) node[anchor=north west] {$l_a$};
    \end{tikzpicture}
    \end{document}
\end{filecontents*}

\begin{filecontents*}{picture2.tex}
    \documentclass{standalone}
    \usepackage{pgf,tikz}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    \begin{document}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \draw [domain=0.08:3.92] plot(\x,{(--1.04--0.32*\x)/1.96});
    \draw (3.6,0.98) node[anchor=north west] {$l_b$};
    \end{tikzpicture}
    \end{document}
\end{filecontents*}

\begin{document}
\begin{minipage}[t]{.45\textwidth}
\includestandalone{picture1}
\captionof{figure}{Some description of figure comes here}
\end{minipage}%
\hfill
\begin{minipage}[t]{.45\textwidth}
\includestandalone{picture2}
\captionof{figure}{Some description of }
\end{minipage}

\end{document}

enter image description here

Or you can use subfigure from subcaption package. In this case you will need float package that provides [H] position specifier.

\documentclass[a4paper,11pt]{article}
\usepackage{standalone}
\usepackage[singlelinecheck=off,hang]{caption}     %% for formatting captions
\usepackage{subcaption}
\usepackage{float}   %% for controlling float position, provides [H] postion specifier.
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}

\usepackage{filecontents}

\begin{filecontents*}{picture1.tex}
    \documentclass{standalone}
    \usepackage{pgf,tikz}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    \begin{document}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \draw [domain=0.08:3.92] plot(\x,{(--1.04--0.32*\x)/1.96});
    \draw (3.6,0.98) node[anchor=north west] {$l_a$};
    \end{tikzpicture}
    \end{document}
\end{filecontents*}

\begin{filecontents*}{picture2.tex}
    \documentclass{standalone}
    \usepackage{pgf,tikz}
    \usetikzlibrary{arrows}
    \pagestyle{empty}
    \begin{document}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \draw [domain=0.08:3.92] plot(\x,{(--1.04--0.32*\x)/1.96});
    \draw (3.6,0.98) node[anchor=north west] {$l_b$};
    \end{tikzpicture}
    \end{document}
\end{filecontents*}

\begin{document}
Some text comes here
\begin{figure}[H]
   \begin{subfigure}[t]{.45\textwidth}
        \includestandalone{picture1}
        \caption{Some description of figure comes here}
    \end{subfigure}%
    \hfill
   \begin{subfigure}[t]{.45\textwidth}
        \includestandalone{picture2}
        \caption{Some description of figure}
    \end{subfigure}
\end{figure}

\end{document}

enter image description here

The same can be achieved with subfig package also. This is left as an exercise.

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.