0

table I want the cells to be vertical middle aligned.

3
  • 9
    Yes, this is possible, but note that in many western countries a table like this would be considered bad typography (so many rules are ugly). Take a look at the multirow package. Commented Jul 24, 2023 at 16:59
  • 3
    And read texdoc.org/pkg/booktabs if you want a sense of why you maybe shouldn't want to do this. :) Commented Jul 24, 2023 at 17:45
  • 2
    Can you update your question title to be more representative of what you're after? "How to do this?" isn't helpful when viewing question snippets in searches. Can you do that? Commented Jul 24, 2023 at 18:50

5 Answers 5

6

In OpTeX, we can use \vspan macro, as described in the documentation, page 16.

\fontfam[lm]
\sans\rm

\table{4{c|}}{\crl
   \vspan2{x=1} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
   \vspan2{x=2} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
   \vspan2{x=3} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
   \vspan2{x=4} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
}
\bye
1
  • 1
    Note, that the question doesn't mention LaTeX, so the answers can be based on various TeX formats. There isn't LaTeX only. So, the negative votes are unair. Maybe, somebody dislikes OpTeX. Commented Jul 26, 2023 at 6:17
3

Here's a solution that employs a single tabular environment.

enter image description here

\documentclass{article}
\usepackage{array}    % for '\extrarowheight' parameter and 'w' column type
\usepackage{multirow} % for '\multirow' macro
\usepackage{arev}     % optional: sans-serif text and math fonts

\begin{document}

\begin{center}
\setlength\extrarowheight{2pt} % default: 0pt

\begin{tabular}{ wc{1.5cm} | wl{1.5cm} | wl{1.5cm} | wc{1.5cm} | }
\hline
\multirow{2.2}{*}{x=1} & abc & xyz & asd, \\
\cline{2-3}
                       & bcd & qwe & pqr  \\
\hline
\multirow{2.2}{*}{x=2} & abc & xyz & asd, \\
\cline{2-3}
                       & bcd & qwe & pqr  \\
\hline
\end{tabular}

\end{center}

\end{document}
1
  • The solution given above uses a uniform width of 1.5cm for all 4 columns. Obviously, you're free to choose other, possibly more suitable, column width values. Commented Jul 24, 2023 at 19:53
2

Solution with use of the tabularray package:

\documentclass[margin=3mm]{standalone}
\usepackage{tabularray} 
\usepackage{arev}     % optional: sans-serif text and math fonts

\begin{document}
\begin{tblr}{hline{odd} = solid, hline{even} = {2-3}{solid}, 
             vline{2-Z} = solid, 
             colspec = {Q[c, wd=15mm, mode=math] *{3}{Q[c, wd=15mm]}}, 
             cell{odd}{1} = {r=2}{} % multi row cells
             }
x=1 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
x=2 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
x=3 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
x=4 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
\end{tblr}
\end{document}

enter image description here

Addendum: or by small variation of above MWE where in last column are used multirow cells too:

\documentclass[margin=3mm]{standalone}
\usepackage{tabularray}
\usepackage{arev}     

\begin{document}
\begin{tblr}{hlines, vline{2-Z} = solid, 
             colspec = {Q[c, wd=15mm, mode=math] *{3}{Q[c, wd=15mm]}}, 
             cell{odd}{1,Z} = {r=2}{} % multi row cells
             }
y=1 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
y=2 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
y=3 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
y=4 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
\end{tblr}

\end{document}

Produced table is similar as before:

enter image description here

1

Here is a solution with {NiceTabular} of nicematrix.

\documentclass[margin=3mm]{standalone}
\usepackage{nicematrix} 

\begin{document}

\begin{NiceTabular}{c|c|c|c|}[hlines]
\Block{2-1}{x=1} & abc & xyz & \Block{2-1}{asd, \\ pqr} \\
    & bcd & qwe \\
\Block{2-1}{x=2} & abc & xyz & \Block{2-1}{asd, \\ pqr} \\
    & bcd & qwe \\
\Block{2-1}{x=3} & abc & xyz & \Block{2-1}{asd, \\ pqr} \\
    & bcd & qwe \\
\Block{2-1}{x=4} & abc & xyz & \Block{2-1}{asd, \\ pqr} \\
    & bcd & qwe \\
\end{NiceTabular}

\end{document}

Output of the above code

0

You can probably achieve this by nesting tabular-environments - each cell itself could be a tabular-environment on it own, tabular-environments in leftmost-column vertically [t]-aligned, tabular-environments in other columns vertically [c]-aligned:

\documentclass{article}
\usepackage{array}
\begin{document}

\sffamily\selectfont

\begin{tabular}{|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|}%
\hline \begin{tabular}[t]{c}$\mathsf{x=1}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{abc}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline 
       \rlap{bcd}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{xyz}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{qwe}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\
\hline \begin{tabular}[t]{c}$\mathsf{x=2}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{a1b1c1}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline
       \rlap{b1c1d1}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{x1y1z1}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{q1w1e1}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\\hline \begin{tabular}[t]{c}$\mathsf{x=3}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{a11b11c11}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline
       \rlap{b11c11d11}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{x11y11z11}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{q11w11e11}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\\hline \begin{tabular}[t]{c}$\mathsf{x=4}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{a111b111c111}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline
       \rlap{b111c111d111}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{x111y111z111}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{q111w111e111}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\
\hline
\end{tabular}
\end{document}

enter image description here

If you decide to specify a width for table-columns, you don't need the combination of \rlap and \hphantom for ensuring equal widths for all tables in one column.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.