0

Is there an option within tabularx to add a vertical whitespace both above and below the table?

\documentclass{article}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\noindent\begin{tabularx}{\textwidth} {XXX} \hline item 11 & item 12 & item 13 \ \hline item 21 & item 22 & item 23 \ \hline \end{tabularx}

\lipsum[1]

\end{document}

enter image description here

I tried to add the verbatimbox package which has a service routine \addvbuffer, but it does not work:

\documentclass{article}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{verbatimbox}

\begin{document}

\lipsum[1]

\addvbuffer[12pt 8pt]{ \noindent\begin{tabularx}{\textwidth} {XXX} \hline item 11 & item 12 & item 13 \ \hline item 21 & item 22 & item 23 \ \hline \end{tabularx} }

\lipsum[1]

\end{document}

enter image description here

EDITED after the @David Carlisle answer:

@David Carlisle, please see here below the errors I get with that solution (might it be something related to Overleaf, that I am using?)

\documentclass{article}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{verbatimbox}

\begin{document}

\lipsum[1] \begin{center} \addvbuffer[12pt 8pt]{%% \noindent\begin{tabularx}{\textwidth} {XXX} \hline item 11 & item 12 & item 13 \ \hline item 21 & item 22 & item 23 \ \hline \end{tabularx}%% }

\end{center}

\lipsum[1]

\end{document}

enter image description here

I get the following errors:

enter image description here enter image description here enter image description here enter image description here

Ommo
  • 835
  • When possible, I would like to avoid the usage of \vspace, since I have several tables - And I would like to have the least number of elements to change, in case I need to adjust some spaces in the document. – Ommo Mar 15 '24 at 10:25
  • 2
    table environment will add necessary spacing for you; a construct is \begin{table}[tbh]<tabular env.>\end{table}. The [tbh] are optional parameters for a table placement: [t]op, [b]ottom, or [h]ere. It's also mandatory if you want to add a \caption{}. – Celdor Mar 15 '24 at 10:36
  • 2
    I assume one of your 7 errors is that \addvbuffer is not defined, which is why [12pt 8pt] is typeset as text to the left of the table in your image. – David Carlisle Mar 15 '24 at 10:37
  • 1
    If the overleaf texlive version is too old, you can contact the support and ask them to move your project to texlive 2024 – samcarter_is_at_topanswers.xyz Mar 15 '24 at 13:54
  • Thanks a lot @samcarter_is_at_topanswers.xyz, I have just contacted the Overleaf Team :-) – Ommo Mar 15 '24 at 13:58
  • 1
    or you can put a newer verbatimbox into your project (I just tried that) but here of course you could simply delete \addvbuffer as it's not doing anything. – David Carlisle Mar 15 '24 at 14:01
  • Thanks @DavidCarlisle :-) – Ommo Mar 15 '24 at 14:56

1 Answers1

2

Note you have 7 errors in that file enter image description here so you shouldn't even look at the layout shown in the pdf which can never be relied on after an error.

tabularx, like tabular does no spacing at all, it is just like a big letter X so remove the \noindent and replace by (say)

\begin{center}
\begin{tabularx}... 
...
\end[center}

The center environment will supply the spacing specified by your documentclass for vertical display constructs.

or in this case place it aroundthe \addvbuffer` (I don't know what that does)

enter image description here

note the missing % added.

\documentclass{article}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{verbatimbox}

\begin{document}

\lipsum[1] \begin{center} \addvbuffer[12pt 8pt]{%% \noindent\begin{tabularx}{\textwidth} {XXX} \hline item 11 & item 12 & item 13 \ \hline item 21 & item 22 & item 23 \ \hline \end{tabularx}%% }

\end{center}

\lipsum[1]

\end{document}

David Carlisle
  • 757,742
  • Thanks a lot...just in case I need to adjust the vertical distances in an asymmetric way (i.e. the above vertical distance different from the below vertical distance), does the center environment allow such fine modifications? – Ommo Mar 15 '24 at 10:40
  • 1
    Maybe a better solution would be to spin a newenvironment and can also have a semantic meaning. – yannisl Mar 15 '24 at 10:41
  • 2
    @Ommo not really but you could define a similar environment (which as yannisl just commented is a good idea anyway) – David Carlisle Mar 15 '24 at 10:42
  • thanks both for your comments :-) – Ommo Mar 15 '24 at 10:42
  • 1
    @Ommo just note ethat within the outer environment call the tabularx as \tabularx \endtabularx. It is all in the manual... – yannisl Mar 15 '24 at 10:44
  • Sorry @DavidCarlisle, me again.... I have just copied and pasted your code from your answer, and I got some errors, like Undefined control sequence.... I am using Overleaf...could it be the reason? – Ommo Mar 15 '24 at 10:46
  • @yannisl Thanks, I think I found \tabularx on page 4 of the manual (https://texdoc.org/serve/tabularx/0)... But I do not understand how to use it... but no problem... thanks for notifying it to me :-) – Ommo Mar 15 '24 at 10:51
  • Hi @DavidCarlisle.... I tried your code, but it does not work... did I miss something? – Ommo Mar 15 '24 at 11:13
  • 1
    the code above works and produces the output shown. you must have made an error but I can not guess, you could at least say which command is undefined which the error message will show but which you have not shown here @Ommo – David Carlisle Mar 15 '24 at 13:25
  • Thanks for your comments David, please see my EDITED question, where I show the errors I get with your code.... – Ommo Mar 15 '24 at 13:49
  • 1
    @Ommo yes you need a newer package or don't use the package at all, why do you need it? see https://www.overleaf.com/read/pstjcjpthkpn#b1fd9a – David Carlisle Mar 15 '24 at 14:02
  • Thanks a lot David! I checked the link you sent me and I can see that that code works there... the textlive 2024? Well, I thought that with that package I could adjust the above and below spaces as I wished... – Ommo Mar 15 '24 at 14:56
  • 1
    @Ommo no look in the overleaf sidebar I uploaded a verbatimbox from an up to date texlive2023 into the project – David Carlisle Mar 15 '24 at 14:57
  • Ah ok, thanks :-) – Ommo Mar 15 '24 at 14:58