1

I would like to generate a figure which I want to embed in another document as PDF. For this I would like to use the standalone class, which I've used before. But now I run into great troubles.

The following MWE works as expected.

\documentclass{article}

\usepackage{subfig}
\usepackage[demo]{graphicx}

\newcommand{\imsize}{0.33\linewidth}

\begin{document}
\begin{figure}[htb]
    \centering
    \subfloat[][Here is some text.]{\includegraphics[width=\imsize]{<figure1>}}
    \subfloat[][Here is some more text.]{\includegraphics[width=\imsize]{<figure1>}}
    \subfloat[][Here is even more text, which should then break on several lines.]{\includegraphics[width=\imsize]{<figure1>}}
\end{figure}
\end{document}

But when I use the standalone class to get a minimal figure PDF, the compilation fails, and I cannot seem to find the culprit, e.g. I get ! LaTeX Error: Something's wrong--perhaps a missing \item. when compiling the code below with latexmk Version 4.45 on Ubuntu 16.04.

\documentclass{standalone}

\usepackage{subfig}
\usepackage[demo]{graphicx}

\newcommand{\imsize}{0.33\linewidth}

\begin{document}
\begin{figure}
    \centering
    \subfloat[][Here is some text.]{\includegraphics[width=\imsize]{<figure1>}}
    \subfloat[][Here is some more text.]{\includegraphics[width=\imsize]{<figure1>}}
    \subfloat[][Here is even more text, which should then break on several lines.]{\includegraphics[width=\imsize]{<figure1>}}
\end{figure}
\end{document}
2
  • The problem is that figure should be \textwidth or \columnwidth in width, There are a number of ways to set \textwidth. I usually use a minipage. Jun 5, 2018 at 10:39
  • @JohnKormylo Thanks for the hint, I'd prefer not to use a minipage.
    – Habi
    Jun 5, 2018 at 12:15

1 Answer 1

4

Add the preview  option:

\documentclass[preview, border=5pt]{standalone}
\usepackage{geometry}
\usepackage{subfig}
\usepackage{graphicx}

\newcommand{\imsize}{0.32\linewidth}

\begin{document}

\begin{figure}
    \centering
    \subfloat[][Here is some text.]{\includegraphics[width=\imsize]{TheLarch}}\enspace
    \subfloat[][Here is some more text.]{\includegraphics[width=\imsize]{TheLarch}}\enspace
    \subfloat[][Here is even more text, which should then break on several lines.]{\includegraphics[width=\imsize]{TheLarch}}
\end{figure}

\end{document} 

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .