# Insert figure in a table, how to align figures with text in a table

I am inserting multiple figures into a table, and would like to make the following change:

1. center the text (1st column) in the cell (all the text currently are at the bottom)

2. center the figures (2nd and 3rd column) so that it doesn't cut the horizontal lines. The figures all have slightly different size. Is there a way to auto-adjust the height of each row so that all figures will fit it?

3. If possible, I would like to show some of the long text in two rows. For example, instead of :

Inverting op-amp (linear amplifier)


I want it to be in two lines, both horizontally centered in the cell:

Inverting op-amp
(linear amplifier)


Any suggestions would be highly appreciated! Thanks!

Here is my latex code:

\begin{table}[ht]
\centering
\begin{tabular}{  p{4.5cm}  p{5cm}  p{5cm}  }      % centered columns (3 columns)
\hline\hline                                      %inserts double horizontal lines
Building Block  & Circuits & Frequency Response \\ [0.5ex] % inserts table heading
\hline
Inverting op-amp
(linear amplifier)
& \includegraphics[height=1in]{figures/servoblockAB.png}& \includegraphics[height=1in]{figures/servoblockAC.png} \\ [1ex]
\hline
Integrator
& \includegraphics[height=1in]{figures/servoblockBB.png}& \includegraphics[height=1in]{figures/servoblockBC.png} \\
\hline
AC integrator with DC gain
& \includegraphics[height=1in]{figures/servoblockCB.png}& \includegraphics[height=1in]{figures/servoblockCC.png} \\
\hline
Differentiator
& \includegraphics[height=1in]{figures/servoblockDB.png}& \includegraphics[height=1in]{figures/servoblockDC.png} \\
\hline
AC differentiator with DC gain
& \includegraphics[height=1in]{figures/servoblockEB.png}& \includegraphics[height=1in]{figures/servoblockEC.png} \\
\hline
\end{tabular}
\caption{A few basic circuit blocks and their frequency response for servo design.}
\label{table4.2}
\end{table}


• Welcome to TeX.SE! A quick hint: If you indent lines containing LaTeX code by four spaces -- easily done by highlighting the lines in question and clicking on the {} "button" in the line above the editing window -- they will be pretty-printed automatically. – Mico Feb 13 '14 at 18:25

I made \Includegraphics (cap I) to insert a picture shifted down half its height. I also used some \linebreaks and \raggedrights.

I also added some gap above/below the pictures, as requested with \addstackgap. I can take an optional argument (default 3pt) to specify the gap.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{stackengine}
\newsavebox\mybox
\newcommand\Includegraphics[2][]{\sbox{\mybox}{%
\includegraphics[#1]{#2}}\abovebaseline[-.5\ht\mybox]{%
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{  p{4.5cm}  p{5cm}  p{5cm}  }      % centered columns (3 columns)
\hline\hline                                      %inserts double horizontal lines
Building Block  & Circuits & Frequency Response \\ [0.5ex] % inserts table heading
\hline
\raggedright Inverting op-amp\linebreak
(linear amplifier)
& \Includegraphics[height=1in]{figures/servoblockAB.png}& \Includegraphics[height=1in]{figures/servoblockAC.png} \\ [1ex]
\hline
Integrator
& \Includegraphics[height=1in]{figures/servoblockBB.png}& \Includegraphics[height=1in]{figures/servoblockBC.png} \\
\hline
\raggedright AC integrator\linebreak with DC gain
& \Includegraphics[height=1in]{figures/servoblockCB.png}& \Includegraphics[height=1in]{figures/servoblockCC.png} \\
\hline
Differentiator
& \Includegraphics[height=1in]{figures/servoblockDB.png}& \Includegraphics[height=1in]{figures/servoblockDC.png} \\
\hline
\raggedright AC differentiator\linebreak with DC gain
& \Includegraphics[height=1in]{figures/servoblockEB.png}& \Includegraphics[height=1in]{figures/servoblockEC.png} \\
\hline
\end{tabular}
\caption{A few basic circuit blocks and their frequency response for servo design.}
\label{table4.2}
\end{table}
\end{document}


• Thanks Steven. I directly copy and paste your code to my document, which is a Thesis template, (I deleted two lines: begin and end document) but it won't compile. I got errors of "undefined control sequence" and "missiong number, treated as zero" for all lines that start with \Includegraphics. Not sure what it means. I would like to attach a picture of the errors, but didn't find where to attach it. – Shun Feb 13 '14 at 21:21
• @Shun It is possible you stackengine.sty is out of date. Could you check? Current version is January 6, 2014 v3.24 – Steven B. Segletes Feb 13 '14 at 21:26
• I am currently using Texstudio 2.3 (SVN 2471), Using Qt Version 4.7.0. Do I have to check specifically the stack version? – Shun Feb 13 '14 at 21:31
• Do I need to re-install the current version? That's frustrating... But thanks for your help anyway! – Shun Feb 13 '14 at 21:33
• Hi Steve, just to let you know that I've fixed the problem by using \begin{figure}[p], instead of \begin{figure}[h]. [p] creates a papge for floats large enough. Thanks! – Shun Feb 17 '14 at 15:58

Another option; I used m{<length>} columns (from the array package) and the features provided by the booktabs package:

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\usepackage[demo]{graphicx}

\begin{document}

\begin{table}[ht]
\centering
\begin{tabular}{  >{\raggedright}m{4.5cm}  m{5cm}  m{5cm}  }      % centered columns (3 columns)
\toprule                                   %inserts double horizontal lines
Building Block  & Circuits & Frequency Response \\  % inserts table heading
Inverting op-amp\\
(linear amplifier)
& \includegraphics[height=1in]{figures/servoblockAB.png}& \includegraphics[height=1in]{figures/servoblockAC.png} \\
Integrator
& \includegraphics[height=1in]{figures/servoblockBB.png}& \includegraphics[height=1in]{figures/servoblockBC.png} \\
AC integrator \\ with DC gain
& \includegraphics[height=1in]{figures/servoblockCB.png}& \includegraphics[height=1in]{figures/servoblockCC.png} \\
Differentiator
& \includegraphics[height=1in]{figures/servoblockDB.png}& \includegraphics[height=1in]{figures/servoblockDC.png} \\
AC differentiator \\ with DC gain
& \includegraphics[height=1in]{figures/servoblockEB.png}& \includegraphics[height=1in]{figures/servoblockEC.png} \\
\bottomrule
\end{tabular}
\caption{A few basic circuit blocks and their frequency response for servo design.}
\label{table4.2}
\end{table}

\end{document}


The table is too wide for standard page layout, since no complete code was provided in the question, I assume some precautions are taken to avoid this in the actual document.

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.