表格垂直对齐

表格垂直对齐

在下表中,我想将前三列与行的垂直中心对齐。尝试了许多解决方案,但都不起作用。MWE:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tabu}
\usepackage{booktabs}

\begin{document}
\pagestyle{empty}
\begin{table}[!ht]
\centering
\caption{Triggermogelijkheden van INT0.}
\setlength{\tabcolsep}{8pt}
\begin{tabu}  {cccX[,l,]}
\toprule
ISC01 & ISC00 & & Omschrijving \\ \midrule
  0   &   0   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3) -- (0.3,0);\draw [ultra thick] (0.3,0.0) -- (1.3,0);\draw (1.3,0) -- (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een laag niveau op de INT0-ingang genereert een interrupt. \\ \midrule
  0   &   1   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3);\draw [ultra thick] (0.3,0.3) -- (0.3,0.0);\draw (0.3,0) -- (1.3,0);\draw [ultra thick] (1.3,0) -- (1.3,0.3);\draw (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een opgaande of neergaande flank op de INT0-ingang genereert een interrupt. \\ \midrule
  1   &   0   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3);\draw [ultra thick] (0.3,0.3) -- (0.3,0.0);\draw (0.3,0) -- (1.3,0);\draw (1.3,0) -- (1.3,0.3);\draw (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een neergaande flank op de INT0-ingang genereert een interrupt. \\  \midrule
  1   &   1   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3);\draw (0.3,0.3) -- (0.3,0.0);\draw (0.3,0) -- (1.3,0);\draw [ultra thick] (1.3,0) -- (1.3,0.3);\draw (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een opgaande flank op de INT0-ingang genereert een interrupt. \\
\bottomrule
\end{tabu}
\end{table}

\end{document}

在此处输入图片描述

答案1

这个例子对我有用

\begin{table}
\centering
\begin{tabular}{|>{\centering\arraybackslash}m{3cm}|>
{\centering\arraybackslash}m{5cm}|} \hline\textbf{Topic} & \textbf{Paragraph}
\\\hline
1 & This is a paragraph. This is a paragraph. This is a paragraph.
\\\hline
\end{tabular}
\end{table}

说实话,我不知道禁忌包。

答案2

我会将文本放入\parbox垂直中心对齐的文本中。

在此处输入图片描述

我在 parbox 的开始和结束处添加了一些结构,您可以根据自己的喜好进行调整(或删除)。

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tabu}
\usepackage{booktabs}

\pgfkeys{%%
  /tikz/present A/.style={},
  /tikz/present B/.style={},
  /tikz/present C/.style={},
  /tikz/present D/.style={},
  /tikz/present E/.style={},
  /tikz/emph A/.code={\tikzset{/tikz/present A/.style={ultra thick}}},
  /tikz/emph B/.code={\tikzset{/tikz/present B/.style={ultra thick}}},
  /tikz/emph C/.code={\tikzset{/tikz/present C/.style={ultra thick}}},
  /tikz/emph D/.code={\tikzset{/tikz/present D/.style={ultra thick}}},
  /tikz/emph E/.code={\tikzset{/tikz/present E/.style={ultra thick}}},
  }

\newcommand\aepic[1]{%%
  \begin{tikzpicture}[#1]
    \draw[present A] (0  ,0.3) -- (0.3,0.3);
    \draw[present B] (0.3,0.3) -- (0.3,0.0);
    \draw[present C] (0.3,  0) -- (1.3,0);
    \draw[present D] (1.3,  0) -- (1.3,0.3);
    \draw[present E] (1.3,0.3) -- (1.6,0.3);
  \end{tikzpicture} 
  }

\newcommand\mytabuparbox[1]{%%
  \parbox{3in}{\raggedright\rule{0pt}{2.5ex}#1\rule[-1.5ex]{0pt}{1pt}}}

\begin{document}

\pagestyle{empty}
\begin{table}[!ht]
\centering
\caption{Triggermogelijkheden van INT0.}
\setlength{\tabcolsep}{8pt}
\begin{tabu}  {cccX[,l,]}
\toprule
ISC01 & ISC00 &                       & Omschrijving \\ \midrule
  0   & 0     & \aepic{emph C}        & \mytabuparbox{Een laag niveau op de INT0-ingang genereert een interrupt.}                  \\ \midrule
  0   & 1     & \aepic{emph B,emph D} & \mytabuparbox{Een opgaande of neergaande flank op de INT0-ingang genereert een interrupt.} \\ \midrule
  1   & 0     & \aepic{emph B}        & \mytabuparbox{Een neergaande flank op de INT0-ingang genereert een interrupt.}             \\ \midrule
  1   & 1     & \aepic{emph D}        & \mytabuparbox{Een opgaande flank op de INT0-ingang genereert een interrupt.}               \\
\bottomrule
\end{tabu}
\end{table}

\end{document}

此外,由于您的 TikZ 代码几乎完全相同,我创建了一个显示基本结构的命令并添加了一些键以获得所需的效果。

答案3

您必须定义单元格对齐方式,如果您有水平对齐选项,以及垂直对齐选项,以控制单元格文本分隔值X column;然后,您必须定义表格宽度并声明每列的大小和每种对齐方式,在这种情况下,列宽与 X 列中的每个数字成比例。请参阅l,c,rp,m,b\tabulinesep\linewidth{X[mc]X[mc]X[mc]X[5m]}禁忌手册,tabu 是包的扩展tabularx,您必须将其包含在您的文档中。

结果:

在此处输入图片描述

梅威瑟:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tabu}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\pagestyle{empty}
\begin{table}[!ht]
\centering
\caption{Triggermogelijkheden van INT0.}
\tabulinesep = 5pt
\begin{tabu} to \linewidth  {X[mc]X[mc]X[mc]X[5m]}
\tabucline -
ISC01 & ISC00 & & Omschrijving \\ \tabucline -
  0   &   0   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3) -- (0.3,0);\draw [ultra thick] (0.3,0.0) -- (1.3,0);\draw (1.3,0) -- (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een laag niveau op de INT0-ingang genereert een interrupt. \\ \tabucline -
  0   &   1   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3);\draw [ultra thick] (0.3,0.3) -- (0.3,0.0);\draw (0.3,0) -- (1.3,0);\draw [ultra thick] (1.3,0) -- (1.3,0.3);\draw (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een opgaande of neergaande flank op de INT0-ingang genereert een interrupt. \\ \tabucline -
  1   &   0   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3);\draw [ultra thick] (0.3,0.3) -- (0.3,0.0);\draw (0.3,0) -- (1.3,0);\draw (1.3,0) -- (1.3,0.3);\draw (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een neergaande flank op de INT0-ingang genereert een interrupt. \\  \tabucline -
  1   &   1   & \begin{tikzpicture}\draw (0,0.3) -- (0.3,0.3);\draw (0.3,0.3) -- (0.3,0.0);\draw (0.3,0) -- (1.3,0);\draw [ultra thick] (1.3,0) -- (1.3,0.3);\draw (1.3,0.3) -- (1.6,0.3);\end{tikzpicture} & Een opgaande flank op de INT0-ingang genereert een interrupt. \\ \tabucline -
\end{tabu}
\end{table}

\end{document}

附录:

如果您想改进以重用 tikz 代码,您可以使用 定义带有条件部分的绘图\ifnum{contdition} drawing_statements \fi,并使用 重用路径坐标并分配名称coordinate(coordinate_name),这样您就可以使用坐标名称在条件绘图中分配一些坐标;在您的示例中,有 3 个切换对象,您可以使用值来控制它们是否出现,例如在\sqwave[#1][#2][#3]{}每个#number控件中控制某些对象是否出现,在这种情况下,如果#number值为 1,则出现。

结果: 在此处输入图片描述

梅威瑟:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tabu}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\pagestyle{empty}
\begin{table}[!ht]
\centering
\caption{Triggermogelijkheden van INT0.}
\tabulinesep = 5pt
\def\sqwave[#1][#2][#3]{
    \begin{tikzpicture}[shorten >=-0.25pt, shorten <=-0.25pt]
        \draw[black!30]
        (0,0.3)
            -- ++ (0.3,0) coordinate (a)
            -- ++ (0,-0.3) coordinate (b)
            -- ++ (1,0) coordinate (c)
            -- ++ (0,0.3) coordinate (d)
            -- ++ (0.3,0);
        \ifnum#1=1 \draw[line width=1.5pt] (a)--(b);\fi
        \ifnum#2=1 \draw[line width=1.5pt] (b)--(c);\fi
        \ifnum#3=1 \draw[line width=1.5pt] (c)--(d);\fi
    \end{tikzpicture}
}
\begin{tabu} to \linewidth  {X[mc]X[mc]X[mc]X[5m]}
\tabucline -
ISC01 & ISC00 & & Omschrijving \\ \tabucline -
  0   &   0   & \sqwave[0][1][0] & Een laag niveau op de INT0-ingang genereert een interrupt. \\ \tabucline -
  0   &   1   & \sqwave[1][0][1] & Een opgaande of neergaande flank op de INT0-ingang genereert een interrupt. \\ \tabucline -
  1   &   0   & \sqwave[1][0][0] & Een neergaande flank op de INT0-ingang genereert een interrupt. \\  \tabucline -
  1   &   1   & \sqwave[0][0][1] & Een opgaande flank op de INT0-ingang genereert een interrupt. \\ \tabucline -
\end{tabu}
\end{table}

\end{document}

相关内容