vertical alignement in texstudio

Asked by At

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

Here is the code:

\documentclass{article}
\usepackage{siunitx}
\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}

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

enter image description here

1 Answers

1
greyshade On

I would suggest using the booktabs package which addresses rules and lines in tables quite well. See its documentation for some notes on table formatting and how to used it. In short, adding

\usepackage{booktabs}

to your preamble will let you use a number of new commands for rules in tables:

\toprule
\midrule
\bottomrule

combining these with your example gives a table looking as follows: booktabs style with additional spacing

or, if you insist on using double rules at top and bottom: double rules with additional spacing

In both cases I don't see the need for your additional '[1em]' space below the top line - without it things would look like this: booktabs style, double rules

This will generate a pdf with all three examples to allow easy comparison:

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}

Using \emph{booktabs} style rules:\\\vskip\baselineskip
\begin{tabular}{lcccc}
  \toprule
    & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$} 
    & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$}  \\[1mm]
  \midrule 
    \textbf{Pure HB-NWs} &  &  &  &   \\
  \bottomrule
\end{tabular}
\vskip\baselineskip
also works without the additional `[1mm]' spacing at the bottom of the line:
\vskip\baselineskip
\begin{tabular}{lcccc}
  \toprule
    & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$} 
    & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$} \\
  \midrule 
    \textbf{Pure HB-NWs} &  &  &  &   \\
  \bottomrule
\end{tabular}
\vskip\baselineskip
\vskip\baselineskip

Using \emph{double rules}:
\vskip\baselineskip
\begin{tabular}{lcccc}
  \midrule\midrule
    & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$} 
    & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$} \\[1mm]
  \midrule 
    \textbf{Pure HB-NWs} &  &  &  &   \\
  \midrule\midrule
\end{tabular}
\vskip\baselineskip
and again without the additional `[1mm]' spacing at the bottom of the line:
\vskip\baselineskip
\begin{tabular}{lcccc}
  \midrule\midrule
    & \textbf{$d_{(O_{1}-Zn/Mg)}(\SI{}{\angstrom})$} 
    & \textbf{$d_{(O_{2}-Zn/Mg)}(\SI{}{\angstrom})$} \\
  \midrule 
    \textbf{Pure HB-NWs} &  &  &  &   \\
  \midrule\midrule
\end{tabular}
\end{document}

On a side note: the 'siunitx' package you're using provides a '\si' command specifically for printing only units, rather than using the '\SI' command with an empty argument; i.e. you might want to use the following:

\si{\angstrom}

rather than:

\SI{}{\angstrom}