3

In the table below, I want to align the first three columns to the vertical center of the row. Tried many solutions but none worked. 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}

enter image description here

1

3 Answers 3

2

this example worked for me

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

I honestly don't know the tabu package.

2
  • It works with tabular but not with tabu. Oct 4, 2018 at 15:26
  • don't use tabu! it is based on old version of array and since it is not maintained, it will not be adopted to changes in array . above proposed solution works fine!
    – Zarko
    Oct 4, 2018 at 23:25
2

I would put the text into a \parbox that's aligned on its vertical center.

enter image description here

I've added some structs at the beginning and end of the parbox which you may tweak (or remove) to your liking.

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

Also, since your TikZ code is virtually all identical, I've created a command that presents the basic structure and added a few keys to get the desired effects.

2

You must define the cell alignment of X column you have the options l,c,r for horizontal align, and p,m,b for vertical, to control the cell text separations you have \tabulinesep value; then you must define the table width to \linewidth and declare the size of each column and each alignment this case {X[mc]X[mc]X[mc]X[5m]} the column width is proportional to each number in the X column. see tabu manual, tabu is an extension of tabularx package, you must include it in your document.

RESULT:

enter image description here

MWE:

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

ADDENDUM:

If you want to improve to reuse the tikz code you could define a drawing with conditional parts using \ifnum{contdition} drawing_statements \fi, and reuse a path coordinates asingning a name using coordinate(coordinate_name), so you can use the coordinate names to asign some in conditional drawings; in your example there are 3 switching objets you can control if they apear or not using values like in \sqwave[#1][#2][#3]{} each #number controls if some apears or not, in this case apears if the #number value is 1.

RESULT: enter image description here

MWE:

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

You must log in to answer this question.

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