5

Could someone please help me to center the equations in this table? This is the first table I'm making in LaTeX, and I can't find the right way to do it.

\begin{center}
\begin{tabular}{ |p{2cm}||p{5cm}|p{5cm}|  }
    \hline
    \multicolumn{3}{|c|}{Erdseilström} \\
    \hline
    &Einfachleitung &Doppelleitung\\[10pt]
    \hline
    1 Erdseil   & $I_N = -\frac{3Z_{NX}}{Z_{NN}} I_0$  &  $I_N= -\frac{6Z_{NX}}{Z_{NN}} I_0$\\[20pt]
    2 Erdseile &   $I_{N_1} = I_{N_2}= -\frac{3Z_{NX}}{Z_{NN}+Z_{N_1N_2}} I_0$   & $I_{N_1}=I_{N_2}=  -\frac{3I_{0}(Z_{NX}+Z_{NY})}{Z_{NN}+Z_{N_1N_2}}$ \\[20pt]
    \hline
\end{tabular}
\end{center}

enter image description here

  • p columns aren't centered – user31729 Mar 6 '18 at 10:17
  • Since line-breaking inside cells wouldn't seem to be desirable, don't use a column type that allows automatic line-breaking. – Mico Mar 6 '18 at 10:21
6

similar to Mico solution. small differences is use amsmath for math writing and makecell for vertical line spacing:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{booktabs, makecell}
\setcellgapes{3pt}

\begin{document}
{\noindent
 \makegapedcells
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l >{$}c<{$} >{$}c<{$}}
    \toprule
    &   \multicolumn{2}{c}{Erdseilström}            \\
    \cmidrule(lr){2-3}
    &   \text{Einfachleitung}
        &   \text{Doppelleitung}                    \\
    \midrule
1 Erdseil
    &   I_N = -\dfrac{3Z_{NX}}{Z_{NN}} I_0
        &   I_N = -\dfrac{6Z_{NX}}{Z_{NN}} I_0      \\
2 Erdseile
    &   I_{N_{1,2}}= -\dfrac{3Z_{NX}}{Z_{NN}+Z_{N_1N_2}} I_0
        &   I_{N_{1,2}}= -\dfrac{3I_{0}(Z_{NX}+Z_{NY})}{Z_{NN}+Z_{N_1N_2}}
                                                    \\
    \bottomrule
\end{tabular*}
}
\end{document}

enter image description here

(red lines indicate text border).

5

I'd like to suggest that you use an array environment, since most of the cells employ math mode. Note that I don't use any vertical lines and fewer, but well-spaced, horizontal lines.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array,booktabs}
\newcolumntype{L}{>{$}l<{$}}  % left-aligned text mode in an "array"
\newcolumntype{C}{>{\displaystyle}c}
\begin{document}

\[
\begin{array}{@{} LCC @{}}
    \toprule
    & \multicolumn{2}{c@{}}{$Erdseilström$} \\
    \cmidrule(l){2-3}
    &$Einfachleitung$ &$Doppelleitung$\\
    \midrule
    1 Erdseil   & I_N = -\frac{3Z_{NX}}{Z_{NN}} I_0  
                & I_N= -\frac{6Z_{NX}}{Z_{NN}} I_0\\
    \addlinespace
    2 Erdseile  & I_{N_1} = I_{N_2}= -\frac{3Z_{NX}}{Z_{NN}+Z_{N_1N_2}} I_0 
                & I_{N_1}=I_{N_2}=  -\frac{3I_{0}(Z_{NX}+Z_{NY})}{Z_{NN}+Z_{N_1N_2}} \\
    \bottomrule
\end{array}
\]
\end{document} 

Addendum to address the OP's follow-up question. If the table must span the full width of the textblock, I'd suggest using a tabular* environment, with its full width set to \textwidth. (The @{\extracolsep{\fill}} bit instructs LaTeX to insert as much intercolumn whitespace as is needed to fill up the target width. The array and tabular environments aren't set up to take a target width as one of their main parameters.)

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array,booktabs}
\newcolumntype{C}{>{$\displaystyle}c<{$}}
\begin{document}

\begingroup  % localize scope of the next instruction
\setlength\tabcolsep{0pt}
\noindent
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} CC } 
\toprule & \multicolumn{2}{c@{}}{Erdseilström} \\ 
\cmidrule(l){2-3} 
&$Einfachleitung$ &$Doppelleitung$\\ 
\midrule 
1 Erdseil  & I_N = -\frac{3Z_{NX}}{Z_{NN}} I_0 
           & I_N = -\frac{6Z_{NX}}{Z_{NN}} I_0\\ 
\addlinespace 
2 Erdseile & I_{N_{1,2}}= -\frac{3Z_{NX}}{Z_{NN}+Z_{N_1N_2}} I_0 
           & I_{N_{1,2}}= -\frac{3I_{0}(Z_{NX}+Z_{NY})}{Z_{NN}+Z_{N_1N_2}} \\
\bottomrule 
\end{tabular*}
\endgroup

\end{document} 
  • Same idea with a little arraystretch for lisibility. – Tarass Mar 6 '18 at 10:21
  • Tnx @Mico, I just changed equations a bit (they are shorter), so how can I strech the table from margin to margin? Here how it looks now:[ \begin{array}{@{} LCC @{}} \toprule & \multicolumn{2}{c@{}}{$Erdseilström$} \\ \cmidrule(l){2-3} &$Einfachleitung$ &$Doppelleitung$\\ \midrule 1 Erdseil & I_N = -\frac{3Z_{NX}}{Z_{NN}} I_0 & I_N= -\frac{6Z_{NX}}{Z_{NN}} I_0\\ \addlinespace 2 Erdseile & I_{N_{1,2}}= -\frac{3Z_{NX}}{Z_{NN}+Z_{N_1N_2}} I_0 & I_{N_{1,2}}= -\frac{3I_{0}(Z_{NX}+Z_{NY})}{Z_{NN}+Z_{N_1N_2}} \\ \bottomrule \end{array} ] – el sol Mar 6 '18 at 10:26
  • 1
    @elsol, please edit your question and put changes there that will be visible to all – Zarko Mar 6 '18 at 10:38
4

Mico's layout is more professional and is to be preferred, but if you want to keep yours:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}
\begin{document}

\begin{center}
\setlength\extrarowheight{10pt}
\begin{tabular}{ |p{2cm}||C{5cm}|C{5cm}|  }
    \hline
    \multicolumn{3}{|c|}{Erdseilström} \\[10pt]
    \hline
    &\multicolumn{1}{c|}{Einfachleitung} &\multicolumn{1}{c|}{Doppelleitung}\\[10pt]
    \hline
    1 Erdseil   & I_N = -\frac{3Z_{NX}}{Z_{NN}} I_0  & I_N= -\frac{6Z_{NX}}{Z_{NN}} I_0\\[20pt]
    2 Erdseile &  I_{N_1} = I_{N_2}= -\frac{3Z_{NX}}{Z_{NN}+Z_{N_1N_2}} I_0   & I_{N_1}=I_{N_2}=  -\frac{3I_{0}(Z_{NX}+Z_{NY})}{Z_{NN}+Z_{N_1N_2}} \\[20pt]
    \hline
\end{tabular}
\end{center}

\end{document}

enter image description here

3

Here is another simple possibility, with the array package. I added some improvements as to the vertical spacing, with the cellspace package, which ensures a minimal padding at the top and bottom of cells in columns with specifier preffixed withe letter S (or C if you load siunitx). Also, I used the medium-sized fractions from nccmath, and hhline for the intersection of double lines:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{mathtools}
\usepackage{nccmath} % provides medium sized formulae and acontrol of intertext spacing via an optional argument

\usepackage{cellspace, hhline}
\setlength{\cellspacetoplimit}{6pt}
\setlength{\cellspacebottomlimit}{6pt}

    \begin{document}

\begin{center}
\begin{tabular}{ |p{2cm}||S{>{\centering\arraybackslash} p{5cm}}|>{\centering\arraybackslash}p{5cm}| }
    \hline
    \multicolumn{3}{|Sc|}{Erdseilström} \\
    \hline
    &Einfachleitung &Doppelleitung\\
    \hhline{-||--}
    1 Erdseil & $I_N = -\mfrac{3Z_{NX}}{Z_{NN}} I_0$ & $I_N= -\mfrac{6Z_{NX}}{Z_{NN}} I_0$\\
    2 Erdseile & $I_{N_1} = I_{N_2}= -\mfrac{3Z_{NX}}{Z_{NN}+Z_{N_1N_2}} I_0$ & $I_{N_1}=I_{N_2}= -\mfrac{3I_{0}(Z_{NX}+Z_{NY})}{Z_{NN}+Z_{N_1N_2}}$ \\
    \hline
\end{tabular}
\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.