在表格中插入图形,如何使表格中的图形与文本对齐

在表格中插入图形,如何使表格中的图形与文本对齐

我正在将多个图形插入到表格中,并想做以下更改:

  1. 将文本(第一列)置于单元格的中心(所有文本当前都在底部)

  2. 将数字(第 2 列和第 3 列)居中,这样它就不会切断水平线。所有数字的大小都略有不同。有没有办法自动调整每行的高度,以便所有数字都适合它?

  3. 如果可能的话,我想将一些长文本显示为两行。例如,而不是:

    Inverting op-amp (linear amplifier)
    

    我希望它分为两行,均在单元格中水平居中:

    Inverting op-amp
    (linear amplifier)
    

任何建议都非常感谢!谢谢!

这是我的乳胶代码:

\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}

在此处输入图片描述

答案1

我制作了\Includegraphics(cap I)来插入一张向下移动一半高度的图片。我还使用了一些\linebreaks 和\raggedrights。

我还根据要求在图片上方/下方添加了一些间隙\addstackgap。我可以使用可选参数(默认 3pt)来指定间隙。

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{stackengine}
\newsavebox\mybox
\newcommand\Includegraphics[2][]{\sbox{\mybox}{%
  \includegraphics[#1]{#2}}\abovebaseline[-.5\ht\mybox]{%
  \addstackgap{\usebox{\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}

在此处输入图片描述

答案2

另一个选择;我使用了m{<length>}列(来自array包)以及所提供的功能booktabs包裹:

\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 
\midrule\addlinespace[1.5ex]
        Inverting op-amp\\
        (linear amplifier)
        & \includegraphics[height=1in]{figures/servoblockAB.png}& \includegraphics[height=1in]{figures/servoblockAC.png} \\
\midrule\addlinespace[1.5ex]
        Integrator 
        & \includegraphics[height=1in]{figures/servoblockBB.png}& \includegraphics[height=1in]{figures/servoblockBC.png} \\
\midrule\addlinespace[1.5ex]
        AC integrator \\ with DC gain
        & \includegraphics[height=1in]{figures/servoblockCB.png}& \includegraphics[height=1in]{figures/servoblockCC.png} \\
\midrule\addlinespace[1.5ex]
        Differentiator
        & \includegraphics[height=1in]{figures/servoblockDB.png}& \includegraphics[height=1in]{figures/servoblockDC.png} \\
\midrule\addlinespace[1.5ex]
        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}

该表格对于标准页面布局来说太宽,由于问题中没有提供完整的代码,我认为在实际文档中采取了一些预防措施来避免这种情况。

选项demo只是graphicx用黑色矩形替换实际图形;不是在实际文档中使用该选项。

在此处输入图片描述

相关内容