5

I am trying to make a pdf figure comprised of several other figures arranged in a table manner. I am using the standalone documentclass. However the results I get are far from optimal. I am using Texstudio for Windows, PDFLatex command on Miktek 2.9: pdflatex.exe -synctex=1 -interaction=nonstopmode %.tex

When using the first two options for the standalone package (in the MWE) I obtain a pdf where the upper and lower sides are cropped but not on left and right sides. When using the varwidth option to true, I obtain the desired cropped edges but the caption titles ((a),(b),...) are all left justified and brackets are gone. Whenever I remove the preview=true option I am filled with errors.

I attach the MWE; in the original, figure (d) is twice as tall as this black box.

%\documentclass[border=2pt,crop=true,preview=true]{standalone} % works but spaces on sides
%\documentclass[border=2pt,preview=true]{standalone} % works but spaces on sides
%\documentclass[varwidth=true,preview=true]{standalone} % works reduces side spaces, but captions ragged left without brackets
\documentclass[varwidth=true]{standalone} % same

\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage{subcaption}

\renewcommand{\tabularxcolumn}[1]{m{#1}} 
\begin{document}
\begin{figure}
    \centering
    \begin{tabularx}{0.75\textwidth}{X X} % @{}
        \begin{tabular}{c} 
            \begin{subfigure}[]{0.99\linewidth}
            \centering
            \includegraphics[width=1\textwidth]{}
            \caption{}
            \label{a}
            \end{subfigure} \\ 
            \begin{subfigure}[]{0.99\linewidth}
            \centering
            \includegraphics[width=1\textwidth]{}
            \caption{}
            \label{b}
            \end{subfigure} \\ 
            \begin{subfigure}[]{0.99\linewidth}
            \centering
            \includegraphics[width=1\textwidth]{}
            \caption{}
            \label{c}
            \end{subfigure}
        \end{tabular}
        & 
        \begin{tabular}{c} 
            \begin{subfigure}[]{0.99\linewidth}
            \centering
            \includegraphics[width=0.99\textwidth]{}
            \caption{}
            \label{d}
            \end{subfigure}
        \end{tabular}
    \end{tabularx}
\end{figure}
\end{document}

I would appreciate your comments on what is going on here and what can be done to solve this problem.

PDF created without varwidth

PDF created with varwidth option

2

First, I have used @{} at appropriate places. Then the subfigure and figure environments are removed. Then it is time to load caption package and use its \captionof macro. This macro is enclosed within a \parbox (a need).

Additionally the subcaption is loaded like

\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}

So the full code will be

\documentclass{standalone}

\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage{caption}
\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}

\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}
    \begin{tabularx}{0.75\textwidth}{@{}X X@{}} % @{}
        \begin{tabular}{@{}c}
            \parbox{\linewidth}{%
            \includegraphics[width=\linewidth]{}
            \captionof{subfigure}{}
            \label{a}
            }
            \\
            \parbox{\linewidth}{%
            \includegraphics[width=\linewidth]{}
            \captionof{subfigure}{}
            \label{b}
            }
            \\
            \parbox{\linewidth}{%
            \includegraphics[width=\linewidth]{}
            \captionof{subfigure}{}
            \label{c}
            }
        \end{tabular}
        &
        \begin{tabular}{@{}c}
            \parbox{\linewidth}{%
            \includegraphics[width=\linewidth]{}
            \captionof{subfigure}{}
            \label{d}
            }
        \end{tabular}
    \end{tabularx}
\end{document}

enter image description here

  • Thanks a lot Harish, worked as intended and responded in less than or about an hour after posting this. Do you know why the figure environment was not adequate for the standalone to work?, I would appreciate it. – RobertoST Oct 2 '15 at 9:31
  • 1
    @RobertoST figure is a float and standalone is meant for producing standalone files. Hence don't use figure with standalone. – user11232 Oct 2 '15 at 9:40

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.