1

I would like to have symmetrical padding at top and bottom of valign=t-ed images. I tried array's \extrarowheight, which introduces some spacing between the images. However, when you add rowcolors, it doesn't look symmetric (it only adds space above, but not below).

Is there a way to

  • Make images A and B not stick together
  • Top-align them with text in first column
  • Vertically center images and text in row color?
\documentclass{article}

\usepackage{mwe} % blindtext, example image
\usepackage{tabularx}
\usepackage{array} % required by tabularx; extrarowheight
\usepackage[export]{adjustbox} % valign
\usepackage[table]{xcolor}

\begin{document}

\rowcolors{1}{gray!20}{}
\setlength\extrarowheight{10pt}

\begin{tabularx}{15cm}{|X|X|}

    Foo &
    \includegraphics[width=\hsize,valign=t]{example-image-a} \\

    \blindtext &
    \includegraphics[width=\hsize,valign=t]{example-image-b} \\

    Bar &
    \includegraphics[width=\hsize,valign=t]{example-image-c} \\

\end{tabularx}

\end{document}

1

You can add below the image the same space as above:

\documentclass{article}

\usepackage{mwe} % blindtext, example image
\usepackage{tabularx}
\usepackage{array} % required by tabularx; extrarowheight
\usepackage[export]{adjustbox} % valign
\usepackage[table]{xcolor}
\usepackage{tikz}
\begin{document}

\rowcolors{1}{gray!20}{}
\setlength\extrarowheight{10pt}

\begin{tabularx}{15cm}{|X|X|}

    Foo &
    \includegraphics[width=\hsize,valign=t,trim=0pt -10pt 0pt 0pt]{example-image-a}\par\vspace{\extrarowheight} \\

    \blindtext &
    \includegraphics[width=\hsize,valign=t]{example-image-b} \\

    Bar &
    \includegraphics[width=\hsize,valign=t]{example-image-c} \\

\end{tabularx}

\end{document}

enter image description here

  • Oh, negative trim! That's smart :) – Laurenz Aug 29 '17 at 17:28
  • Actually I wanted to remove this (it was from my first try but the trim gave a too small space). I'm not quite sure why one needs both values. – Ulrike Fischer Aug 29 '17 at 17:35
0

To add some padding at the top and bottom of cells in a symmetricway, you can load cellspace, which defines a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you load siunitx.

You also can play with the padding= llx lly urx ury key of adjustbox.

Finally, to have the text in l.h.s. cells centred w.r.t. the image, change the definition of the X column type as m{some length} instead of p.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{mwe} % blindtext, example image
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage[export]{adjustbox} % valign
\usepackage[table]{xcolor}
\renewcommand{\tabularxcolumn}[1]{>{\RaggedRight\arraybackslash}m{#1}}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{5pt}
\setlength{\cellspacebottomlimit}{5pt}
\addparagraphcolumntypes{X}

\begin{document}

\rowcolors{1}{gray!20}{}
\noindent\begin{tabularx}{\linewidth}{|S{X}|X|}

    Foo &
    \includegraphics[width=\hsize,valign=t]{example-image-a} \\

    \blindtext &
    \includegraphics[width=\hsize,valign=t, padding = 0ex 2ex 0ex 2ex]{example-image-b} \\

    Bar &
    \includegraphics[width=\hsize,valign=t, padding = 0ex 0ex 0ex 2ex]{example-image-c} \\
\end{tabularx}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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