[Tex/LaTex] Center vertically in tabularx with modified height

tabularxvertical alignment

I would like to :

  • center vertically the content in a row
  • change the height of the row

Here is an attempt:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\tabularxcolumn}[1] {m{#1}}

\begin{document}
\renewcommand{\arraystretch}{4}
\begin{tabularx}{\linewidth}{|*{2}{Y|}}
        \hline 
        test & test \\ \hline
\end{tabularx}

\end{document}

but it does not work.

What is the best way to handle tables in an easy and highly customisable way? How to to solve the present issue?

Thanks

enter image description here


EDIT: The solution of Zarko does not work, as shown in this MWE: the text is not entered vertically.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell,tabularx}
\setcellgapes{12pt}
\newcolumntype{Y}{>{\centering\arraybackslash}X}


\begin{document}
{
\makegapedcells
\begin{tabularx}{\linewidth}{|*{2}{Y|}}
        \hline
    This is a longer line, this is a longer line, this is a longer line & test \\
        \hline
\end{tabularx}
}
\end{document}

enter image description here

Best Answer

  • context of your table is not known so i can only guess that you like to have above and below of cells' contents more vertical space, for example 12pt. this can be done (in case, that table hasn't colored rows or columns) with help of makecell package:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell,tabularx}
\setcellgapes{12pt}
\newcolumntype{Y}{>{\centering\arraybackslash}X}


\begin{document}
{
\makegapedcells
\begin{tabularx}{\linewidth}{|*{2}{Y|}}
        \hline
    test & test \\
        \hline
\end{tabularx}
}
\end{document}

edit:

  • alternative solutionis use cellspace pacakge and in cells with multi line content use \parbox{\linewidth}{...} (unfortunately makecell doesn't work with m column types, and cellspace has problems with multi lines contents too).

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{cellspace, tabularx}
\setlength\cellspacetoplimit{12pt}
\setlength\cellspacebottomlimit{12pt}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

%------------- show page layout. don't use this in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

\begin{document}
\noindent
\begin{tabular}{|*{2}{S{C{\dimexpr0.5\linewidth-2\tabcolsep-\arrayrulewidth}}|}
                }
    \hline
test & \parbox{\linewidth}{\centering\lipsum[11]}  \\
    \hline
\end{tabular}
\end{document}

enter image description here

Related Question