4

In fact, I want the vectors of tension to be centered on the middle and I don't know why there is no space between "vectors of tension". Also, the way the state of switches are presented isn't good. I want to have a good form of this table.

Here is the code that I used:

 \documentclass{article}
 \usepackage{amsmath}
 \usepackage{array}
 \renewcommand{\arraystretch}{1.3}
 \usepackage{booktabs}
 \usepackage{multirow}
 \usepackage{caption}
 \begin{document}

   \begin{table}
   \centering
   \caption{Les tensions délivrées par l'onduleur selon l'état des
     interrupteurs}
   \begin{tabular}{@{} c c c  c c c c @{}}
   \toprule
   $Vectors of tension$ & \multicolumn{3}{c}{state of switchs}  &
   \multicolumn{3}{c}{Output voltage} \\
   \cmidrule(l){2-4}
   \cmidrule(l){5-7}
    & a & b & c  & $V_a$ & $V_b$ & $V_c$ \\
   \midrule
   $V_0$ & 0  &  0 & 0 & 0 & 0 & 0  \\ \\
   $V_1$ & 1  &  0 & 0 & $2U_{dc}$/3 & $-U_{dc}$/3 & $-U_{dc}$/3 \\ \\
   $V_2$ & 1  &  1 & 0 & $U_{dc}$/3 & $U_{dc}$/3 & $-2U_{dc}$/3 \\ \\
   $V_3$ & 0  &  1 & 0 & $-U_{dc}$/3 & $2U_{dc}$/3 & $-U_{dc}$/3 \\ \\
   $V_4$ & 0  &  1 & 1 & $-2U_{dc}$/3 & $U_{dc}$/3 & $U_{dc}$/3 \\ \\
   $V_5$ & 0  &  0 & 1 & $-U_{dc}$/3 & $-U_{dc}$/3 & $2U_{dc}$/3 \\ \\
   $V_6$ & 1  &  0 & 1 & $U_{dc}$/3 & $-2U_{dc}$/3 & $U_{dc}$/3 \\ \\
   $V_7$ & 1  &  1 & 1 & 0 & 0 & 0 \\ \\
   \bottomrule
   \end{tabular}
   \end{table}
 \end{document}
4

If you put something within $...$ LaTeX thinks it is a mathematical expression.

To improve the "State of switches" columns, you can use p{...} column type.

I've used also \makecell for the first column header.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\renewcommand{\arraystretch}{1.3}
\newcolumntype{P}{>{\centering\arraybackslash$}p{1.6em}<{$}}
\newcolumntype{C}{>{\centering\arraybackslash$}c<{$}}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{caption}

\begin{document}

    \begin{table}
        \centering
        \caption{Les tensions délivrées par l'onduleur selon l'état des 
            interrupteurs}
        \begin{tabular}{@{} C *3P *3C @{}}
            \toprule
            \multirow{2}{*}{\makecell{Vectors\\ of\\ tension}} & \multicolumn{3}{c}{State of switches}  & 
            \multicolumn{3}{c}{Output voltage} \\
            \cmidrule(lr){2-4}
            \cmidrule(lr){5-7}
            & a& b & c  & V_a & V_b & V_c \\ 
            \midrule
            V_0 & 0  &  0 & 0 & 0 & 0 & 0  \\[1ex]
            V_1 & 1  &  0 & 0 & 2U_{dc}/3 & -U_{dc}/3 & -U_{dc}/3 \\[1ex]
            V_2 & 1  &  1 & 0 & U_{dc}/3 & U_{dc}/3 & -2U_{dc}/3 \\[1ex]
            V_3 & 0  &  1 & 0 & -U_{dc}/3 & 2U_{dc}/3 & -U_{dc}/3 \\[1ex]
            V_4 & 0  &  1 & 1 & -2U_{dc}/3 & U_{dc}/3 & U_{dc}/3 \\[1ex]
            V_5 & 0  &  0 & 1 & -U_{dc}/3 & -U_{dc}/3 & 2U_{dc}/3 \\[1ex]
            V_6 & 1  &  0 & 1 & U_{dc}/3 & -2U_{dc}/3 & U_{dc}/3 \\[1ex]
            V_7 & 1  &  1 & 1 & 0 & 0 & 0 \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

enter image description here

Edit:

If you don't want to redefine \arraystretch, you could fine-tune the vertical position of the \multirow like this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\newcolumntype{P}{>{\centering\arraybackslash$}p{1.6em}<{$}}
\newcolumntype{C}{>{\centering\arraybackslash$}c<{$}}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{caption}

\begin{document}

    \begin{table}
        \centering
        \caption{Les tensions délivrées par l'onduleur selon l'état des 
            interrupteurs}
        \begin{tabular}{@{} C *3P *3C @{}}
            \toprule
            \multirow{2}{*}[-.5ex]{\makecell{Vectors\\ of tension}} & \multicolumn{3}{c}{State of switches}  & 
            \multicolumn{3}{c}{Output voltage} \\
            \cmidrule(lr){2-4}
            \cmidrule(lr){5-7}
            & a& b & c  & V_a & V_b & V_c \\ 
            \midrule
            V_0 & 0  &  0 & 0 & 0 & 0 & 0  \\[1.5ex]
            V_1 & 1  &  0 & 0 & 2U_{dc}/3 & -U_{dc}/3 & -U_{dc}/3 \\[1.5ex]
            V_2 & 1  &  1 & 0 & U_{dc}/3 & U_{dc}/3 & -2U_{dc}/3 \\[1.5ex]
            V_3 & 0  &  1 & 0 & -U_{dc}/3 & 2U_{dc}/3 & -U_{dc}/3 \\[1.5ex]
            V_4 & 0  &  1 & 1 & -2U_{dc}/3 & U_{dc}/3 & U_{dc}/3 \\[1.5ex]
            V_5 & 0  &  0 & 1 & -U_{dc}/3 & -U_{dc}/3 & 2U_{dc}/3 \\[1.5ex]
            V_6 & 1  &  0 & 1 & U_{dc}/3 & -2U_{dc}/3 & U_{dc}/3 \\[1.5ex]
            V_7 & 1  &  1 & 1 & 0 & 0 & 0 \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

enter image description here

However, you could modify \arraystretch for one table only, see here: Separate \arraystretch value for every table.

  • Everything is good but there is a problem look below – kerdouj kardouj Jul 28 '18 at 20:29
  • Do you have \renewcommand{\arraystretch}{1.3} in your actual document? – CarLaTeX Jul 28 '18 at 20:31
  • @CarLaTeX, i would not encourage op to his wrong use \\ \\ to make more vertical space between table rows. it should be replaced with something else (for example with \\[1ex]). – Zarko Jul 28 '18 at 20:40
  • Isn't ther another way to enlarge the sapce instead of renewcommand{\arraystretch}{1.3} – kerdouj kardouj Jul 28 '18 at 21:12
  • @kerdoujkardouj See my edit. – CarLaTeX Jul 29 '18 at 5:24
3

I would focus most of my effort on making the table, and especially the material in the final three columns, more visually appealing and thus more readable. I also suggest using a tabular* environment, with width set to \textwidth, instead o the basic tabular environment. By spreading things out more in the horizontal direction, it's also less necessary (if at all) to spread things out vertically. Finally, by judiciously defining new column types whose contents are in math mode automatically, most $ symbols in the body of the table can be omitted, greatly de-cluttering the LaTeX code.

enter image description here

\documentclass{article}
 \usepackage[french]{babel}
 \usepackage[T1]{fontenc}
 \usepackage{booktabs,amsmath,array}
 \newcolumntype{C}{>{$}c<{$}}
 \newcolumntype{R}{>{$}r<{$}}
 \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
 \usepackage[skip=0.333\baselineskip]{caption}
 \newcommand\mycell[1]{\smash{%
     \begin{tabular}[t]{c}#1\end{tabular}}}
 \newcommand\mc[1]{\multicolumn{1}{C}{#1}} % handy shortcut macro

\begin{document}
\begin{table}
\setlength\tabcolsep{0pt} % let LaTeX figure out intercol. whitespace
\caption{Les tensions délivrées par l'onduleur selon 
         l'état des interrupteurs}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} C *{3}{P{7mm}} *{3}{R} }
   \toprule
   \mycell{Vectors\\of tension}
   & \multicolumn{3}{c}{Switch States}  
   & \multicolumn{3}{c}{Output Voltage} \\
   \cmidrule{2-4}
   \cmidrule{5-7}
   & a & b & c & \mc{V_a} & \mc{V_b} & \mc{V_c} \\ 
   \midrule
   V_0 & 0 & 0 & 0 & \mc{0} & \mc{0} & \mc{0} \\
   V_1 & 1 & 0 & 0 & 2U_{\!dc}/3 & -U_{\!dc}/3 & -U_{\!dc}/3 \\
   V_2 & 1 & 1 & 0 &  U_{\!dc}/3 &  U_{\!dc}/3 &-2U_{\!dc}/3 \\
   V_3 & 0 & 1 & 0 & -U_{\!dc}/3 & 2U_{\!dc}/3 & -U_{\!dc}/3 \\
   \addlinespace
   V_4 & 0 & 1 & 1 &-2U_{\!dc}/3 &  U_{\!dc}/3 &  U_{\!dc}/3 \\
   V_5 & 0 & 0 & 1 & -U_{\!dc}/3 & -U_{\!dc}/3 & 2U_{\!dc}/3 \\
   V_6 & 1 & 0 & 1 & U_{\!dc}/3 & -2U_{\!dc}/3 &  U_{\!dc}/3 \\
   V_7 & 1 & 1 & 1 & \mc{0} & \mc{0} & \mc{0} \\
   \bottomrule
\end{tabular*}
\end{table}
\end{document}

Addendum: To make the material in the final three columns really readable, it's a good idea to express the quantities in terms of multiples of the base voltage unit, viz., $U_{dc}/3$. Just be sure to provide a legend to explain to reader what the base voltage unit is.

enter image description here

\documentclass{article}
 \usepackage[french]{babel}
 \usepackage[T1]{fontenc}
 \usepackage[skip=0.333\baselineskip]{caption}
 \usepackage{booktabs,array}
 \newcolumntype{C}{>{$}c<{$}}
 \newcolumntype{R}{>{$}r<{$}}
 \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
 \newcommand\mycell[1]{\smash{%
     \begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}
 \newcommand\mc[1]{\multicolumn{1}{C}{#1}} % handy shortcut macro

\begin{document}
\begin{table}
\centering
\setlength{\tabcolsep}{12pt} % default value: 5pt
\caption{Les tensions délivrées par l'onduleur selon 
         l'état des interrupteurs}
\begin{tabular}{@{} *{4}{C} *{3}{R} @{}}
   \toprule
   \mycell{Vectors\\of tension}
   & \multicolumn{3}{c}{Switch states}  
   & \multicolumn{3}{c@{}}{Output voltage$^{*}$} \\
   \cmidrule(lr){2-4}
   \cmidrule(l){5-7}
   & a & b & c & V_a & V_b & V_c \\ 
   \midrule
   V_0 & 0 & 0 & 0 &  0 &  0 &  0 \\
   V_1 & 1 & 0 & 0 &  2 & -1 & -1 \\
   V_2 & 1 & 1 & 0 &  1 &  1 & -2 \\
   V_3 & 0 & 1 & 0 & -1 &  2 & -1 \\
   \addlinespace
   V_4 & 0 & 1 & 1 & -2 &  1 &  1 \\
   V_5 & 0 & 0 & 1 & -1 & -1 &  2 \\
   V_6 & 1 & 0 & 1 &  1 & -2 &  1 \\
   V_7 & 1 & 1 & 1 &  0 &  0 &  0 \\
   \bottomrule
   \addlinespace
   \multicolumn{7}{@{}l@{}}{\footnotesize $^{*}$ Output voltages are expressed in multiples of $U_{\!dc}/3$.}\\
\end{tabular}
\end{table}
\end{document}
2

enter image description here

Use tabularx with \newcolumntype{C}{ >{ \arraybackslash \Centering } X } to define new column types that will automatically be set to have equal width. If you want to adjust the width of certain columns as a percentage of the reference column width, use >{\hsize=factor\hsize}C. For instance, >{\hsize=0.7\hsize}C means that the column will have 70% of the reference column width.

Also, if you desire more spacing between each row and the next, it is more convenient to use \renewcommand{\arraystretch}{1.7} instead of multiple \\ macros after each row.

Here is the code for the output above

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\renewcommand{\arraystretch}{1.7}

\usepackage{multirow}
\usepackage{caption}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{C}{ >{ \arraybackslash \Centering } X }
\usepackage{booktabs}
\usepackage{makecell}


 \begin{document}


\begin{table}
   \centering
    \caption{Les tensions délivrées par l'onduleur selon l'état des 
     interrupteurs}
    \begin{tabularx}{1\textwidth}{C !{\vrule width 0.2mm} @{\extracolsep{1.5mm}}>{\hsize=0.6\hsize}C >{\hsize=0.6\hsize}C  >{\hsize=0.6\hsize}C @{\extracolsep{2mm}}C C C}
       \toprule
       \multirow{2}{=}{\Centering Vectors of  Tension} & \multicolumn{3}{c}{State of Switches}  &
       \multicolumn{3}{c}{Output voltage} \\
       \Xcline{2-4}{0.2mm}
       \Xcline{5-7}{0.2mm}
        & a & b & c  & $V_a$ & $V_b$ & $V_c$ \\ 
       \Xhline{0.25mm}
       $V_0$ & 0  &  0 & 0 & 0 & 0 & 0  \\
       $V_1$ & 1  &  0 & 0 & $2U_{dc}$/3 & $-U_{dc}$/3 & $-U_{dc}$/3 \\
       $V_2$ & 1  &  1 & 0 & $U_{dc}$/3 & $U_{dc}$/3 & $-2U_{dc}$/3 \\
       $V_3$ & 0  &  1 & 0 & $-U_{dc}$/3 & $2U_{dc}$/3 & $-U_{dc}$/3 \\
       $V_4$ & 0  &  1 & 1 & $-2U_{dc}$/3 & $U_{dc}$/3 & $U_{dc}$/3 \\
       $V_5$ & 0  &  0 & 1 & $-U_{dc}$/3 & $-U_{dc}$/3 & $2U_{dc}$/3 \\
       $V_6$ & 1  &  0 & 1 & $U_{dc}$/3 & $-2U_{dc}$/3 & $U_{dc}$/3 \\
       $V_7$ & 1  &  1 & 1 & 0 & 0 & 0 \\
        \bottomrule
    \end{tabularx}
\end{table}



\end{document}
  • i wouldn't use vertical rules with rules defined in booktabs. result is (as you can see) ugly :-( – Zarko Jul 28 '18 at 21:06
  • The \midrule can be replaced with \Xhline{0.2mm} from makecell package, but there is still a gap to the right of Vectors of Tension. How can we use \cmidrule and close that gap? – Al-Motasem Aldaoudeyeh Jul 28 '18 at 21:16
  • and what you not use in your answer? i would not use vertical rules. makecell also define Xcline, in your case \Xcline{2-4}{1.2pt} – Zarko Jul 28 '18 at 21:21
  • I solved it now :) – Al-Motasem Aldaoudeyeh Jul 28 '18 at 21:36
1

Using an array instead of a tabular and typeset the values flushright:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}{>{\Centering}p{1.6em}}
\usepackage{booktabs}
\usepackage{caption}
\newcommand\MC[1]{\multicolumn{1}{c}{#1}}
\def\0{\MC{0}}
\begin{document}

\begin{table}
\centering
\renewcommand{\arraystretch}{1.5}
\caption{Les tensions délivrées par l'onduleur selon l'état des interrupteurs}
$\begin{array}{@{} c *3P *3r @{}}\toprule
\makebox(30,-10){\shortstack{Vectors\\ of\\ tension}} & 
  \multicolumn{3}{c}{\text{State of switches}}  & 
    \multicolumn{3}{c}{\text{Output voltage}} \\\cmidrule(lr){2-4}\cmidrule(lr){5-7}
    & a  & b & c & \MC{V_a}   & \MC{V_b}   & \MC{V_c} \\ \midrule
V_0 & 0  & 0 & 0 & \0         & \0         & \0  \\
V_1 & 1  & 0 & 0 & 2U_{dc}/3  & -U_{dc}/3  & -U_{dc}/3 \\
V_2 & 1  & 1 & 0 & U_{dc}/3   & U_{dc}/3   & -2U_{dc}/3 \\
V_3 & 0  & 1 & 0 & -U_{dc}/3  & 2U_{dc}/3  & -U_{dc}/3 \\
V_4 & 0  & 1 & 1 & -2U_{dc}/3 & U_{dc}/3   & U_{dc}/3 \\
V_5 & 0  & 0 & 1 & -U_{dc}/3  & -U_{dc}/3  & 2U_{dc}/3 \\
V_6 & 1  & 0 & 1 & U_{dc}/3   & -2U_{dc}/3 & U_{dc}/3 \\
V_7 & 1  & 1 & 1 & \0         & \0         & \0 \\
\bottomrule
\end{array}$
\end{table}

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