2

I am making a table with LaTeX, and I have trouble with vertical alignment of the texts. When I have \hline, the text crosses the line.

Here is the code:

\begin{tabular}{lcccc}
\hline\hline
 & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$} 
 & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$} 
 & \textbf{$d_{(O_{3}-Zn/Mg)}(\SI{}{\angstrom})$} 
 & \textbf{$d_{(O_{\bot}-Zn/Mg)}(\SI{}{\angstrom})$} \\[1mm]
\hline 
\textbf{Pure HB-NWs} &  &  &  &   \\
\hline\hline
\end{tabular}

Also I enclosed the undesired result to make my point clear. Please let me know how I can solve this problem.

enter image description here

  • Remember to accept one of the answers if you find any of them useful. – Svend Tveskæg Aug 1 '14 at 9:00
4

There are a few problems with your table:

  • You shouldn't use \hline. Instead, use \...rule from the booktabs package.
  • Putting \textbf around a math expression has no effect; if you want bold math, use \mtathbf.
  • If you use \ce from the mhchem package when typesetting chemical elements, you get the correct output.
  • Here, use \si{<unit>} instead of \SI{<number>}{<unit>}.
  • The subscripts, say (O_{1} - \ce{Zn}/\ce{Mg}) (after my edit), look wierd. What is the exact meaning of this? (It depends on how it should be typeset.)

Here is how I would typeset the table:

\documentclass{article}

\usepackage[margin = 3cm]{geometry} % to avoid `overfull \hbox'
\usepackage[version = 4]{mhchem}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{l *{4}{c}}
  \toprule
    & $d_{(O_{1} - \ce{Zn}/\ce{Mg})}(\si{\angstrom})$
    & $d_{(O_{2} - \ce{Zn}/\ce{Mg})}(\si{\angstrom})$
    & $d_{(O_{3} - \ce{Zn}/\ce{Mg})}(\si{\angstrom})$
    & $d_{(O_{\bot} - \ce{Zn}/\ce{Mg})}(\si{\angstrom})$ \\
  \midrule
    \textbf{Pure HB-NWs} & & & & \\
  \bottomrule
\end{tabular}

\end{document}

output1

Or maybe

\documentclass{article}

\usepackage[margin = 4cm]{geometry} % to avoid `overfull \hbox'
\usepackage[version = 3]{mhchem}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{l *{4}{c}}
  \toprule
     & $d_{(O_{1} - \ce{Zn}/\ce{Mg})}$
     & $d_{(O_{2} - \ce{Zn}/\ce{Mg})}$
     & $d_{(O_{3} - \ce{Zn}/\ce{Mg})}$
     & $d_{(O_{\bot} - \ce{Zn}/\ce{Mg})}$ \\[0.5ex]
     & \si{\angstrom}
     & \si{\angstrom}
     & \si{\angstrom}
     & \si{\angstrom} \\
  \midrule
    \textbf{Pure HB-NWs} & & & & \\
  \bottomrule
\end{tabular}

\end{document}

output2

P.S. TeXstudio is the editor; that has nothing to do with your table.

2

The package booktabs changes the spacing between lines and the table cells. It uses the commands \toprule and \bottomrule for thicker lines (you used a double \hline for it) and midrule inside the table. Vertical lines are problematic in booktabs and this solution somewhat changes your layout, but maybe it helps:

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{lcccc}
\toprule
 & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$} 
 & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$} 
 & \textbf{$d_{(O_{3}-Zn/Mg)}(\SI{}{\angstrom})$} 
 & \textbf{$d_{(O_{\bot}-Zn/Mg)}(\SI{}{\angstrom})$} \\[1mm]
\midrule
\textbf{Pure HB-NWs} &  &  &  &   \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

1

You can set extrarowheight with the help of array package.

\documentclass{article}
\usepackage{siunitx}
\usepackage{array}
\setlength{\extrarowheight}{2pt} %% adjust suitably
\begin{document}
  \begin{tabular}{lcccc}
\hline\hline
 & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$}
 & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$}
 & \textbf{$d_{(O_{3}-Zn/Mg)}(\SI{}{\angstrom})$}
 & \textbf{$d_{(O_{\bot}-Zn/Mg)}(\SI{}{\angstrom})$} \\[1mm]
\hline
\textbf{Pure HB-NWs} &  &  &  &   \\
\hline\hline
\end{tabular}
\end{document}

enter image description here

Or add an invisible rule in the particular row:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
  \begin{tabular}{lcccc}
\hline\hline
\rule{0ex}{3ex}             %%% adjust 3ex suitably.
 & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$}
 & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$}
 & \textbf{$d_{(O_{3}-Zn/Mg)}(\SI{}{\angstrom})$}
 & \textbf{$d_{(O_{\bot}-Zn/Mg)}(\SI{}{\angstrom})$} \\[1mm]
\hline
\textbf{Pure HB-NWs} &  &  &  &   \\
\hline\hline
\end{tabular}
\end{document}
  • I would use \si{\angstrom} instead of \SI{}{\angstrom} though. – user11232 Jul 30 '14 at 11:11

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.