2

Consider the following MRE where you would notice that it's difficult for the average reader to see the bars above Q and k.

\documentclass[11pt]{article}
\begin{document}
\begin{tabular}{|c|c|}
\hline
    cell 1 & cell2 \\ \hline
    $\bar{k}$ & $\bar{Q}$ \\ \hline
\end{tabular}
\end{document}

enter image description here

How do I fix this issue? I don't really mind whether you insert a vertical space above the letters or use a more clever way -- I'm simply looking for a solution to this issue without having to write a lot of code (so that I can remember it and reproduce later when needed).

7
  • 1
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for the users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Commented Aug 13 at 12:01
  • 2
    Remove the vertical lines and use \toprule, \midrule and \bottomrule of package booktabs instead of hline for better formatting of tabulars.
    – cabohah
    Commented Aug 13 at 12:02
  • You wouldn't have this problem with tabularray, it has better spacing by default: i.sstatic.net/82cK18HT.png Commented Aug 13 at 12:03
  • @samcarter_is_at_topanswers.xyz Made the necessary changes, it wasn't tedious at all. (I didn't require any package.)
    – user326459
    Commented Aug 13 at 12:05
  • @user326459 Great to hear it wasn't tedious, then it won't be a problem to directly include a MWE in all your future questions! Commented Aug 13 at 12:07

2 Answers 2

1

You could use the tabularray package. It has a less crowed spacing by default and thus avoids the problem:

\documentclass[11pt]{article}

\usepackage{tabularray}

\begin{document}

\begin{tblr}{|c|c|}
\hline
    cell 1 & cell2 \\ \hline
    $\bar{k}$ & $\bar{Q}$ \\ \hline
\end{tblr}

\end{document}

enter image description here

3
  • Works like a charm! Thank you. (Note: I'll accept your answer once the site lets me, which is in about 7 minutes apparently.)
    – user326459
    Commented Aug 13 at 12:08
  • 1
    @user326459 Before you accept, please consider the comment by cabohah. Redesigning your table would make it look much more professional. Commented Aug 13 at 12:10
  • I did. The spacing is improved and the thickened borders look better.
    – user326459
    Commented Aug 13 at 12:19
1

I can think of two main solution methods. The first treats the symptom (by inserting a suitable typographic strut), while the second fixes the underlying problem (caused by non-existent vertical spacing adjustments around \hline directives). The second solution also provides a more open "look" by getting rid of the unneeded vertical lines.

enter image description here

\documentclass[11pt]{article}
\usepackage{booktabs} % for \toprule, \midrule, and \bottomrule macros

\begin{document}

\begin{tabular}[t]{|c|c|}
    \hline
    header 1 & header 2 \\ \hline
    $\bar{k}$ & $\bar{Q}$ \\ 
    \hline
\end{tabular}
\quad 
% fix 1: treat the symptom
\begin{tabular}[t]{|c|c|}
    \hline
    header 1 & header 2 \\
    \hline
    $\bar{k}$ & $\bar{Q}^{\strut}$ \\ \hline
\end{tabular}
\quad 
% fix 2: treat the underlying problem
\begin{tabular}[t]{@{} cc @{}}
    \toprule
    header 1 & header 2 \\ 
    \midrule
    $\bar{k}$ & $\bar{Q}$ \\ 
    \bottomrule
\end{tabular}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .