3

I'm trying to create an array containing plot elements (from the CircuiTikZ package but it's incidental) some of which writes are on multiple lines .

As I want the texts to be centered vertically and horizontally, I went with this code:

\documentclass[border=2mm]{standalone}

\usepackage{array,multirow,makecell,hhline}
\setcellgapes{1pt}
\makegapedcells
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}
\usepackage[utf8]{inputenc}
\usepackage[siunitx, european, straightvoltages, cute inductors]{circuitikz}


\begin{document}
\begingroup
\makegapedcells
\setcellgapes{3pt}
\tikzset{every picture/.style={baseline=-0.5ex}}
\begin{tabular}{|C{4cm}|C{4cm}|C{3cm}|}
\hline
Composant & Code & Image résultant\\
\hline
amplificateur opérationnel anglo-saxon & node[op amp]{} & \begin{circuitikz}
                    \draw (0,0) node[op amp]{};
                  \end{circuitikz} \\
\cline{1-3}
amplificateur opérationnel européen & node[en amp]{} & \begin{circuitikz}
            \draw (0,0) node[en amp]{};
         \end{circuitikz} \\
\cline{1-3}
   amplificateur opérationnel entièrement différentiel & node[fd op amp]{} & \begin{circuitikz}
                        \draw (0,0) node[fd op amp]{};
                            \end{circuitikz} \\  
    \cline{1-3}
   amplificateur d'instrumentation & node[inst amp]{} & \begin{circuitikz}
                        \draw (0,0) node[inst amp]{};
                            \end{circuitikz} \\         
    \cline{1-3}
   amplificateur d'instrumentation avec résistance & node[inst amp ra]{} & \begin{circuitikz}
                        \draw (0,0) node[inst amp ra]{};
                            \end{circuitikz} \\ 
    \cline{1-3}
      
    \hhline{|=|=|=|}
    \end{tabular}
\endgroup
\end{document}

My problem is that for a line (the 4th), the text is no longer vertically centered but it is placed at the top of the cell (I also have the impression that the vertical centering of the other lines is not not very correct). How can I solve this problem?

Thank you

1
  • Remark: You don't need \usepackage[utf8]{inputenc} any longer in modern LaTeX distributions. Mar 29, 2021 at 13:56

3 Answers 3

2

You should use m column instead of b ones. However, makecell seems incompatible with m columns.

I suggest you to use nicematrix.

\documentclass[border=2mm]{standalone}
\usepackage{nicematrix,hhline}
\usepackage[siunitx, european, straightvoltages, cute inductors]{circuitikz}
\newcolumntype{C}[1]{>{\centering\arraybackslash }m{#1}}

\begin{document}

\begin{NiceTabular}{|C{4cm}|C{4cm}|C{3cm}|}[cell-space-limits=3pt]
\hline
Composant & Code & Image résultant\\
\hline
amplificateur opérationnel anglo-saxon & node[op amp]{} & \begin{circuitikz}
                    \draw (0,0) node[op amp]{};
                  \end{circuitikz} \\
\hline
amplificateur opérationnel européen & node[en amp]{} & \begin{circuitikz}
            \draw (0,0) node[en amp]{};
         \end{circuitikz} \\
\hline
   amplificateur opérationnel entièrement différentiel & node[fd op amp]{} & \begin{circuitikz}
                        \draw (0,0) node[fd op amp]{};
                            \end{circuitikz} \\  
\hline
   amplificateur d'instrumentation & node[inst amp]{} & \begin{circuitikz}
                        \draw (0,0) node[inst amp]{};
                            \end{circuitikz} \\         
\hline
   amplificateur d'instrumentation avec résistance & node[inst amp ra]{} & \begin{circuitikz}
                        \draw (0,0) node[inst amp ra]{};
                            \end{circuitikz} \\ 
\hhline{|=|=|=|}
\end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

0

If there is fixed width specified for all columns, you need not any macro based on \halign primitive. \halign is able to calculate the columns width by the widest item in each column but this in not the feature needed here. You can use ditectly \hbox, \vcenter, \hrule \vrule primitives (without \halign):

\documentclass[border=2mm]{standalone}
\usepackage{circuitikz}

\begin{document}

\vbox{\hrule
   \def\p#1#2#3{\hbox{\vrule\c{4cm}{#1}\c{4cm}{#2}\c{4cm}{#3}}\hrule}
   \def\c#1#2{$\vcenter{\medskip\hsize=#1\parindent=0pt\leftskip=5pt plus1fill
                     \rightskip=\leftskip #2\par\medskip}$\vrule}
\p {Composant} {Code} {Image résultant}
\p {amplificateur opérationnel anglo-saxon} {node[op amp]} 
   {\begin{circuitikz}\draw (0,0) node[op amp]{};\end{circuitikz}}
\p {amplificateur opérationnel européen} {node[en amp]} 
   {\begin{circuitikz}\draw (0,0) node[en amp]{};\end{circuitikz}}
\p {amplificateur opérationnel entièrement différentiel} {node[fd op amp]}  
   {\begin{circuitikz}\draw (0,0) node[fd op amp]{};\end{circuitikz}}  
\p {amplificateur d'instrumentation} {node[inst amp]} 
   {\begin{circuitikz}\draw (0,0) node[inst amp]{};\end{circuitikz}}         
\p {amplificateur d'instrumentation avec résistance} {node[inst amp ra]}  
   {\begin{circuitikz}\draw (0,0) node[inst amp ra]{};\end{circuitikz}} 
}

\end{document}
0

You don't need to make gaped cells, it's sufficient to instruct TikZ to add something to the bounding box.

\documentclass[a4paper]{article}

\usepackage{array,tabularx}

\usepackage[siunitx, european, straightvoltages, cute inductors]{circuitikz}


\begin{document}

\begingroup\renewcommand{\tabularxcolumn}{m}
%\tikzset{every picture/.style={baseline=-0.5ex}}
\tikzset{
  every picture/.style={
    execute at end picture={
      \path (current bounding box.south west) rectangle
            (current bounding box.north east)+(0,0.15);
    },
  },
}
\noindent
\begin{tabularx}{\textwidth}{
  | >{\centering}X
  | >{\centering}X
  | >{\centering\arraybackslash}X |
}
\hline
Composant & Code & Image résultant\\
\hline
amplificateur opérationnel anglo-saxon &
  node[op amp]{} &
  \begin{circuitikz}
    \draw (0,0) node[op amp]{};
  \end{circuitikz} \\
\hline
amplificateur opérationnel \\ européen &
  node[en amp]{} &
  \begin{circuitikz}
    \draw (0,0) node[en amp]{};
    \path ++(0,1.1);
  \end{circuitikz} \\
\hline
amplificateur opérationnel entièrement \\ différentiel &
  node[fd op amp]{} &
  \begin{circuitikz}
    \draw (0,0) node[fd op amp]{};
  \end{circuitikz} \\  
\hline
amplificateur d'instrumentation &
  node[inst amp]{} &
  \begin{circuitikz}
    \draw (0,0) node[inst amp]{};
  \end{circuitikz} \\         
\hline
amplificateur d'instrumentation \\ avec résistance &
  node[inst amp ra]{} &
  \begin{circuitikz}
    \draw (0,0) node[inst amp ra]{};
  \end{circuitikz} \\ 
\hline
\end{tabularx}
\endgroup

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