2

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.7\textwidth}|
                                      >{\centering\arraybackslash}wc{0.1\textwidth}|
                                      >{\centering\arraybackslash}wc{0.1\textwidth}|
                                      }
                                      \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}

1 Answer 1

2

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 >{\centering\arraybackslash}wc{0.1\textwidth} with w{c}{0.1\textwidth}. Put differently, please drop the >{\centering\arraybackslash} "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.7\textwidth}|  % <-- use 'm', not 'p', col. type
                         w{c}{0.1\textwidth}|
                         w{c}{0.1\textwidth}|
                       }
             \hline
             Title & Something & Something \\ 
             \hline\hline
                          
            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) &  \\ 
            \hline\hline
        \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 \renewcommand\tabularxcolumn[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.1\textwidth} 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}
\renewcommand\tabularxcolumn[1]{m{#1}} % for vertical centering
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{booktabs} % for well-spaced horizontal rules

\begin{document}
\begin{table}[h]
   %\renewcommand{\arraystretch}{1.4}
   \setlength\extrarowheight{2pt}
   \begin{tabularx}{\textwidth}{|L|c|c|}
      \hline
      Title & Something & Something \\ 
      \hline\hline
      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) &  \\ 
      \hline\hline
   \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}

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.