Vertical text alignment in latex table

tablesvertical alignment

I have created the following table.

Image

I need rows "Text", "Same here" and "I want this to align vertically" to be vertically aligned. I have searched similar questions, and used suggestions from Vertical alignment in tabular cells with variable height and How to vertically-center the text of the cells?, but their solutions split my table. Please let me know where I am going wrong. My MWE is shown below:

\documentclass[12pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage[font=scriptsize,
        labelfont=bf]{caption}
\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{pdflscape}
\usepackage{lipsum}
\UseTblrLibrary{siunitx}

\begin{document}
\begin{table}[]
\begin{tabular}{cccccccccccc}
\hline
\multicolumn{4}{|c|}{I want this to align vertically}                                                                                                                                                                                                                                    
& \multicolumn{4}{c|}{I want this to align vertically}                                                                                                                                                                                                                                    
& \multicolumn{4}{c|}{I want this to align vertically}                                                                                                                                                                                                                                    
\\ [20pt] \hline
\multicolumn{4}{|c|}{Text}                                                                                                                                                                                                                                                               
& \multicolumn{4}{c|}{Text}                                                                                                                                                                                                                                                               
& \multicolumn{4}{c|}{Text}                                                                                                                                                                                                                                                               
\\ [15 pt]\hline
\multicolumn{1}{|c|}{\multirow{\begin{tabular}[c]{@{}c@{}}Same\\ here\end{tabular}}} & 
\multicolumn{1}{c|}{\multirow{\begin{tabular}[c]{@{}c@{}}Same\\ here\end{tabular}}} & 
\multicolumn{2}{c|}{\begin{tabular}[c]{@{}c@{}}Ambient\\ Conditions\end{tabular}} & 
\multicolumn{1}{c|}{\multirow{\begin{tabular}[c]{@{}c@{}}Vertically\\ align\end{tabular}}} & 
\multicolumn{1}{c|}{\multirow{\begin{tabular}[c]{@{}c@{}}Same\\ here\end{tabular}}} & 
\multicolumn{2}{l|}{\begin{tabular}[c]{@{}l@{}}Ambient\\ Conditions\end{tabular}} & 
\multicolumn{1}{c|}{\multirow{\begin{tabular}[c]{@{}c@{}}Same\\ here\end{tabular}}} & 
\multicolumn{1}{c|}{\multirow{\begin{tabular}[c]{@{}c@{}}Same\\ here\end{tabular}}} & 
\multicolumn{2}{c|}{\begin{tabular}[c]{@{}c@{}}Ambient\\ Conditions\end{tabular}} \\ \cline{3- 
4} \cline{7-8} \cline{11-12} 
\multicolumn{1}{|c|}{}                                                                            
& \multicolumn{1}{c|}{}                                                                            
& \multicolumn{1}{c|}{RH}                 & \multicolumn{1}{c|}{Temp}               & 
\multicolumn{1}{c|}{}                                                                            
& \multicolumn{1}{c|}{}                                                                            
& \multicolumn{1}{l|}{RH}                 & \multicolumn{1}{l|}{Temp}               & 
\multicolumn{1}{c|}{}                                                                            
& \multicolumn{1}{c|}{}                                                                            
& \multicolumn{1}{c|}{RH}                 & \multicolumn{1}{c|}{Temp}               \\ \hline
\multicolumn{1}{|c|}{A}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{A}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{A}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                \\ \hline
\multicolumn{1}{|c|}{B}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{B}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{B}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                \\ \hline
\multicolumn{1}{|c|}{C}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{C}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{C}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                \\ \hline
\multicolumn{1}{|c|}{D}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{D}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{D}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                \\ \hline
\multicolumn{1}{|c|}{E}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{E}                                                                           
& \multicolumn{1}{c|}{200}                                                                         
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                & 
\multicolumn{1}{c|}{E}                                                                           
& \multicolumn{1}{c|}{200}                                                                          
& \multicolumn{1}{c|}{200}                & \multicolumn{1}{c|}{200}                \\ \hline
\multicolumn{1}{l}{}                                                                              
& \multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                    & \multicolumn{1}{l}{}                    & 
\multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                    & \multicolumn{1}{l}{}                    & 
\multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                    & \multicolumn{1}{l}{}                    \\    
\multicolumn{1}{l}{}                                                                              
& \multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                    & \multicolumn{1}{l}{}                    & 
\multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                    & \multicolumn{1}{l}{}                    & 
\multicolumn{1}{l}{}                                                                             
& \multicolumn{1}{l}{}                                                                                 
& \multicolumn{1}{l}{}                    & \multicolumn{1}{l}{}                   
\end{tabular}
\end{table}
\end{document}      

I appreciate it may be a duplicate question and apologise for the inconvenience, but I am very new to Latex. Many thanks in advance.

Best Answer

  • Your table is quite big: 12 columns! So it spill out of text area.
  • In preamble you load tabularray package, why you not use it in design of this table? It is powerful package! Code with it is very simple (regardless that is somehow different what you learn at table settings at other (classic) tables packages and require some effort to learn it)
  • Since you load tabularray package and already receive two answers using it, which you accepted) I assume, that you at least a little familiar with it, so I strongly encourage to further use it:
\documentclass[12pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage[font=scriptsize,
        labelfont=bf]{caption}
\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{pdflscape}
\UseTblrLibrary{siunitx}
\usepackage{lipsum}

\begin{document}
    \begin{table}[ht]
\begin{tblr}{width=\linewidth,
             hlines, vlines,
             colspec={*{12}{X[c,m]}},
             colsep=4pt,
             row{1}={ht=7ex},
             row{2}={ht=5ex},
             hspan=minimal
            } 
\SetCell[c=4]{c} I want this to align vertically
    &   &   &   &   \SetCell[c=4]{c} I want this to align vertically
        &   &   &   &   \SetCell[c=4]{c} I want this to align vertically
            &   &   &                                                   \\
\SetCell[c=4]{c} Text
    &   &   &   &   \SetCell[c=4]{c} Text
        &   &   &   &   \SetCell[c=4]{c} Text
            &   &   &                                                   \\
\SetCell[r=2]{c} {Same\\ here}
    &   \SetCell[r=2]{c} {Same\\ here}
        &   \SetCell[c=2]{c} {Ambient\\ Conditions}
            &   &   \SetCell[r=2]{c} {Same\\ here}
                    &   \SetCell[r=2]{c} {Same\\ here}
                        &   \SetCell[c=2]{c} {Ambient\\ Conditions}
                            &   &   \SetCell[r=2]{c} {Same\\ here}
                                    &   \SetCell[r=2]{c} {Same\\ here}
                                        &   \SetCell[c=2]{c} {Ambient\\ Conditions}
                                            &                           \\
    &     & RH  & Temp &   &    & RH  & Temp &  &   & RH  & Temp        \\
A   & 200 & 200 & 200  & A & 200 & 200  & 200 & A   & 200 & 200 & 200   \\ 
B   & 200 & 200 & 200  & B & 200 & 200  & 200 & B   & 200 & 200 & 200   \\
C   & 200 & 200 & 200  & C & 200 & 200  & 200 & C   & 200 & 200 & 200   \\
D   & 200 & 200 & 200  & D & 200 & 200  & 200 & D   & 200 & 200 & 200   \\
E   & 200 & 200 & 200  & E & 200 & 200  & 200 & E   & 200 & 200 & 200   \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

Note, I would consider to use in table \small font size. It can be determined by adding \small before \begin{tblr}.

Edit: improved is table specification and added more explanation.