# Error: “Undefined control sequence” in \includegraphics, height

I am using figure and subfigure environment. Inside subfigure I am using includegraphics. The figure and subfigure structure looks like following:

\begin{figure}
\begin{subfigure}[b]{.25\textwidth}
\centering
\includegraphics[width=.9\linewidth,keepaspectratio]{building1}
\caption{\textit{\small{building1}}}
\label{fig:1a}
\end{subfigure}
\begin{subfigure}[b]{.75\textwidth}
\centering
\includegraphics[width=.9\linewidth,height=100\lineheight pt,keepaspectratio]{building2}
\caption{\textit{\small{building2}}}
\label{fig:1b}
\end{subfigure}
\caption{\textit{\small{Buildings}}}
\label{fig:1}
\end{figure}


For the first subfigure, everything is OK. But for the second I am getting the build error: Undefined control sequence. ...t pt,keepaspectratio]{building2}. It seems the problem lies with using the height attribute in the second subfigure, as when I removed the height attribute from the second subfigure, there was no build error.

What is the reason of this? Is there a way to keep using both height and width attributes in includegraphics?

P.S.: I am using \usepackage{subcaption}.

• Welcome to TeX.SX! \lineheight is not defined by default. Perhaps you want \baselineskip instead. – Andrew Swann Jul 16 '15 at 9:48
• height=100\baselineskip should instead be something like height=0.85\textheight to allow space for the caption. – egreg Jul 16 '15 at 10:24
• \lineheight pt <- maybe the pt is a problem? – Thomas Weise Jul 16 '15 at 10:28

By default, LaTeX has no parameter \lineheight. I guess that may be you mean \baselineskip instead which is the stand vertical space between the corresponding points of lines in text.

Replacing \lineheight with \baselineskip removes the error, but has no effect in your case, as you have also specified the width and keepaspectratio. You should remove one of these extra specification to allow the resizing to take place. I have chose to remove keepaspectratio below.

You will then discover that 100\baselineskip is more than a standard page height, so in the example below I have reduced this to 10\baselinkeskip.

\documentclass{article}

\usepackage{graphicx,subcaption}

\captionsetup{font=small,textfont=it}

\begin{document}
\begin{figure}
\begin{subfigure}[b]{.25\textwidth}
\centering
\includegraphics[width=.9\linewidth,keepaspectratio]{example-image-a}
\caption{Building 1}
\label{fig:1a}
\end{subfigure}
\begin{subfigure}[b]{.75\textwidth}
\centering
\includegraphics[width=.9\linewidth,height=10\baselineskip]{example-image-b}
\caption{Building 2}
\label{fig:1b}
\end{subfigure}
\caption{Buildings}
\label{fig:1}
\end{figure}
\end{document}


In the above, I have also used a \captionsetup command to specify uniform styling of the captions. This avoids having to write \small\textit in each case, and leads to more consistency.