4

I'm trying to create simple table with tikz pictures and its descriptions on the left side. Unfortunately I cannot vertically center those descriptions in their cells:

\documentclass[a4paper,fleqn,leqno]{article}
\usepackage{polyglossia}
\usepackage{tikz,tikz-3dplot,graphicx}
\usepackage{array,multirow,tabu}
\newcolumntype{C}[3]{@{\hspace*{#1}}>{\centering\arraybackslash}p{#2}@{\hspace*{#3}}}
\newcolumntype{R}[2]{>{\raggedleft\arraybackslash}p{#1}@{\hspace*{#2}}}
\newcolumntype{L}[2]{@{\hspace*{#1}}>{\raggedright\arraybackslash}p{#2}}
\begin{document}

{\renewcommand\arraystretch{1.1}
\begin{tabular}{|C{0pt}{100pt}{0pt}|C{0pt}{200pt}{0pt}|}
\hline
\multicolumn{1}{|C{0pt}{100pt}{0pt}|}{Modulační signál} & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\
\hline
moduluje amplitudu nosného signálu & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\
\hline
moduluje frekvenci nosného signálu & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\
\hline
\end{tabular}}\\[1cm]

{\tabulinesep=1.2mm
\begin{tabu}{|c|c|}
\hline
Modulační signál & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\\hline
moduluje amplitudu nosného signálu & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\\hline
moduluje frekvenci nosného signálu & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\\hline
\end{tabu}}

\end{document}

I tried tabular:
enter image description here
and tabu:
enter image description here
environment. tabu gives slightly better output.
How can I vertically center those descriptions?

5

I define a style which I call my pic adjust to be applied to each of the \tikz commands in the tabular environment:

\tikzset{my pic adjust/.style={%%
  baseline=(current bounding box.center),
  execute at end picture={\path (current bounding box.north) -- ++ (0,4pt);
                          \path (current bounding box.south) -- ++ (0,-4pt);
                          }%
  }}

The idea here is first to set the baseline for the \tikz command. By default, with any picture, the baseline is at the bottom of the picture. So, I explicitly define the baseline to be the center of the picture. You can adjust this to something more suitable if the center isn't quite right looking to you. Secondly there is no buffer around the picture and so without further adjustments the picture bumps into the horizontal lines for your table. To get around this, I tweak the bounding box by adding an offset (of 4pt) to the current bounding box.

However, we can do a bit better. .style allows allows an argument to be passed. So to facilitate fine-tuning of the picture's baseline, I modified the above code as follows:

\tikzset{my pic adjust/.style={%%
  baseline=(my center),
  execute at end picture={\path (current bounding box.north) -- ++ (0,4pt);
                          \path (current bounding box.south) -- ++ (0,-4pt);
                          \path (current bounding box.center) -- ++ (0,#1) coordinate (my center);
                          }%
  },
 my pic adjust/.default=0pt,
}

By also providing my pic adjust/.default=0pt, I set the default value for my pic adjust so that it needn't always be explicitly set if you feel no adjustment above the picture center is necessary.

Here at the end of the picture, in addition to tweaking the bounding box, I add a coordinate that I call my center, which I use for the baseline setting. my center is a new coordinate displaced vertically from the center of the bounding box.

It's this lastest version of my pic adjust that I use here:

\documentclass[a4paper,fleqn,leqno]{article}
\usepackage{polyglossia}
\usepackage{tikz,tikz-3dplot,graphicx}
\usepackage{array,multirow,tabu}
\newcolumntype{C}[3]{@{\hspace*{#1}}>{\centering\arraybackslash}p{#2}@{\hspace*{#3}}}
\newcolumntype{R}[2]{>{\raggedleft\arraybackslash}p{#1}@{\hspace*{#2}}}
\newcolumntype{L}[2]{@{\hspace*{#1}}>{\raggedright\arraybackslash}p{#2}}
\tikzset{my pic adjust/.style={%%
  baseline=(my center),
  execute at end picture={\path (current bounding box.north) -- ++ (0,4pt);
                          \path (current bounding box.south) -- ++ (0,-4pt);
                          \path (current bounding box.center) -- ++ (0,#1) coordinate (my center);
                          }%
  },
my pic adjust/.default=0pt,
}

\begin{document}

{\renewcommand\arraystretch{1.1}
\begin{tabular}{|C{0pt}{100pt}{0pt}|C{0pt}{200pt}{0pt}|}
\hline
\multicolumn{1}{|C{0pt}{100pt}{0pt}|}{Modulační signál} & 
  \tikz[my pic adjust=-2pt] \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\
\hline
moduluje amplitudu nosného signálu & \tikz[my pic adjust=4pt] \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\
\hline
moduluje frekvenci nosného signálu & \tikz[my pic adjust=4pt] \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\
\hline
\end{tabular}}\\[1cm]

{\tabulinesep=1.2mm
\begin{tabu}{|c|c|}
\hline
Modulační signál & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\\hline
moduluje amplitudu nosného signálu & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\\hline
moduluje frekvenci nosného signálu & \tikz \draw[domain=-(pi/2):((7/2)*pi),smooth,variable=\x,thick,scale=0.5] plot ({\x},{sin(\x r)}); \\\hline
\end{tabu}}

\end{document}

I didn't tweak anything in the tabu table. I'll leave that for you.

enter image description here

2

by set tizpicture baseline to current bounding box.center. for additional vertical space i suggest to use gaped cell defined in the package makecell. as tabular environmemt can be handy tabulary, however it works also with p{...} column type:

\documentclass[a4paper,fleqn,leqno]{article}
\usepackage{polyglossia}
\usepackage{tikz}
\usepackage{makecell, tabularx}

\begin{document}

\begin{center}
\setcellgapes{5pt}
\makegapedcells
\tikzset{line/.style={draw=red, very thick, domain=-pi/2:7*pi/2, samples=60}}

\begin{tabularx}{.88\linewidth}{| >{\raggedright}X | l |}
    \hline
Modulační\newline
signál
    &   \tikz[baseline=(current bounding box.center)]
        \draw [line] plot (0.5*\x,{sin(\x r)});     \\
    \hline
moduluje amplitudu nosného signálu
    &   \tikz[baseline=(current bounding box.center)]
        \draw[line] plot (0.5*\x,{sin(\x r)});      \\
    \hline
moduluje frekvenci nosného signálu
    &   \tikz[baseline=(current bounding box.center)]
        \draw[line] plot (0.5*\x,{sin(\x r)});      \\
    \hline
\end{tabularx}
\end{center}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.