Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Remember to accept one of the answers if you find any of them useful. –  Svend Tveskæg Aug 1 at 9:00

3 Answers 3

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}
share|improve this answer
    
I would use \si{\angstrom} instead of \SI{}{\angstrom} though. –  Harish Kumar Jul 30 at 11:11

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 = 3]{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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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