TransWikia.com

Cell vertically centered

TeX - LaTeX Asked on February 1, 2021

Is there a simple way to center the cell that contains "Q (2)" vertically?

documentclass[12pt,paper=a4,addpoints,cancelspace]{exam}
usepackage{array}
usepackage{censor}
censorruledepth=-.2ex
censorruleheight=.1ex

begin{document}
noindent


        begin{table}[h]
        begin{center}
        scriptsize
        label{1}
        scriptsize
        renewcommand{arraystretch}{1.4}
        begin{tabular}{|p{0.7textwidth}|
                                      >{centeringarraybackslash}wc{0.1textwidth}|
                                      >{centeringarraybackslash}wc{0.1textwidth}|
                                      }
                                      hline
            Title &Something &Something  hline
            hline
                          
            2. Apply the concepts of basic vector spaces topics to Rn and to the solution spaces of the ordinary
differential equations. & Q (2) &   hline
            hline
        end{tabular}
        end{center}
        vspace{-0.5em}
end{table}

end{document}

One Answer

Since you load the array package, you may achieve your formatting objective by replacing the p column type with the m column type for column 1.

Whatever else you may choose do, please replace >{centeringarraybackslash}wc{0.1textwidth} with w{c}{0.1textwidth}. Put differently, please drop the >{centeringarraybackslash} "prefix" of sorts.

enter image description here

documentclass[12pt,paper=a4,addpoints,cancelspace]{exam}
usepackage{array,amssymb}
usepackage{censor}
censorruledepth=-.2ex
censorruleheight=.1ex

begin{document}
%noindentn% redundant

begin{table}[h]
        centering % use "centering" rather than a "center" environment
        scriptsize
        %label{1} "label" doesn't have desired effect unless preceded by "caption" 
        renewcommand{arraystretch}{1.4}
        begin{tabular}{|m{0.7textwidth}|  % <-- use 'm', not 'p', col. type
                         w{c}{0.1textwidth}|
                         w{c}{0.1textwidth}|
                       }
             hline
             Title & Something & Something  
             hlinehline
                          
            2. Apply the concepts of basic vector spaces topics 
               to $mathbb{R}^n$ and to the solution spaces of 
               the ordinary differential equations. & 
            Q (2) &   
            hlinehline
        end{tabular}
end{table}
end{document}

Addendum: Another way to achieve the desired vertical centering -- other than to use an explicit m column type rather than a p column type -- is to employ a tabularx environment and to run the instruction renewcommandtabularxcolumn[1]{m{#1}}. This works because the X column type defined by the tabularx package is is p-column with a "twist" -- the fact that LaTeX calculates its width automatically, as a residual.

For the following screenshot, I've done away with the scriptsize directive (mainly because I don't understand its purpose) and replaced both instances of w{c}{0.1textwidth} with c. The upper tabularx environment continues the baroque look with lots of vertical and horizontal rules; the lower tabularx environment removes a lot of that cruft by doing away with all vertical rules and using fewer, but well-spaced, horizontal rules.

enter image description here

documentclass[12pt,paper=a4,addpoints,cancelspace]{exam}
usepackage{array,amssymb}
usepackage{censor}
censorruledepth=-.2ex
censorruleheight=.1ex

usepackage{tabularx}
renewcommandtabularxcolumn[1]{m{#1}} % for vertical centering
newcolumntype{L}{>{raggedrightarraybackslash}X}
usepackage{booktabs} % for well-spaced horizontal rules

begin{document}
begin{table}[h]
   %renewcommand{arraystretch}{1.4}
   setlengthextrarowheight{2pt}
   begin{tabularx}{textwidth}{|L|c|c|}
      hline
      Title & Something & Something  
      hlinehline
      2. Apply the concepts of basic vector spaces topics 
         to $mathbb{R}^n$ and to the solution spaces of 
         the ordinary differential equations. 
      & Q (2) &   
      hlinehline
   end{tabularx}

   vspace{1cm}
   % same structure, but without any vertical rules, and with fewer, but well-spaced, horizontal rules
   begin{tabularx}{textwidth}{@{} Lcc @{}}
      toprule
      Title & Something & Something  
      midrule
      2. Apply the concepts of basic vector spaces topics 
         to $mathbb{R}^n$ and to the solution spaces of 
         the ordinary differential equations. 
      & Q (2) &   
      bottomrule
   end{tabularx}   

end{table}
end{document}

Answered by Mico on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP