1

I want make a table as @Zarko's answer in Reduce Space Before Table and Between Table to New Section. But I have a problem:

enter image description here

The "text" in first row does not center of cell. This is the code:

\documentclass[a4paper,oneside,11pt]{book}
\usepackage[hmargin={4cm,3cm},vmargin={4cm,3cm}]{geometry}
\usepackage{array}
\usepackage{longtable, makecell, tabularx}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}
\usepackage{amsmath}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{newtxmath}
\usepackage[labelsep=period]{caption}
\usepackage{lipsum}

\makeatletter
\g@addto@macro\normalsize{%
    \setlength\abovedisplayskip{2pt}
    \setlength\belowdisplayskip{2pt}
    \setlength\abovedisplayshortskip{0pt}
    \setlength\belowdisplayshortskip{0pt}
}
\makeatother

\begin{document}
    \lipsum[1-4]
    \begingroup
    \setcellgapes{3pt}
    \makegapedcells
    \begin{longtable}{|c|c|c|c|}
        \caption{That is my longtable, which is supposed to reproduce my problem}
        \label{:tab:longtable}          \\
        \hline
        \thead{text} & \thead{text} & \thead{text} & \thead{text}   \\
        \hline
        \endfirsthead
        \caption[]{That is my longtable, which is supposed 
            to reproduce my problem (cont.)}             \\
        \hline
        \thead{text} & \thead{text} & \thead{text} & \thead{text}   \\
        \hline
        \endhead
        \multicolumn{4}{r @{}}{\small\emph{continue on the next page}}  \\*
        \multicolumn{4}{@{} l}{\small Source: cnihe3i3nixom}    \\
        \endfoot
        \hline
        \endlastfoot
        %%%% table nody    
        Variable 1   & Variable 2   & Variable 3   & variable 4     \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
        \hline
        uxbwyy       & xneio22xi    & nc33i3       & 44444          \\
    \end{longtable}
    \endgroup
    \lipsum[6-8]
    \[\int \sin x dx = -\cos x +c\]
    where $c$ is constant.
\end{document}

If I omit the code:

\makeatletter
    \g@addto@macro\normalsize{%
        \setlength\abovedisplayskip{2pt}
        \setlength\belowdisplayskip{2pt}
        \setlength\abovedisplayshortskip{0pt}
        \setlength\belowdisplayshortskip{0pt}
    }
\makeatother

the "text" in first row can centered but there is gap before and after the equation:

enter image description here

So, I want both of decreasing gap size of equation and centering the "text" in first row.

Anyone can help me to do that?

1
  • 2
    Replace\ thead with `\textbf``. This should help in table(s). Showed space above/below equation I can't reproduce
    – Zarko
    Commented Jan 30, 2021 at 7:32

1 Answer 1

2
  • more space around column headers written by \thead is determined by design, so if you not liked it, than don't use it. Replace it by \textbf:

enter image description here

  • I can't reproduce bigger vertical space around your equation, but observe discrepancy between math and text font height.
  • you should be aware, that helvet font is about 20% higher than math font defined in newtxmath.
  • for removing this remedy you have two possibilities:
    • used scaled helvet fonts:
\usepackage[scaled=0.82]{helvet}
\renewcommand{\familydefault}{\sfdefault}
  • instead helvet fonts use newtxtext, which is better paired with newtxmath:
\usepackage{newtxtext, newtxmath}
\renewcommand{\familydefault}{\sfdefault}

Use of not scaled helvet:

enter image description here

Use of scaled helvet:

enter image description here

Use of newtxtext:

\renewcommand{\familydefault}{\sfdefault}

You must log in to answer this question.

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