1

Question: Here i am working with a simple table in which i am finding that some text are not centrally(vertically) align. How can i solve this issue?

MWE:

\documentclass[12pt]{article}
\usepackage[
a4paper,top=1in,bottom=1in,left=0.7in,right=0.7in,headheight=14.5pt,]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{forest}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{intersections}

\begin{document}
\large
\begin{center}
    \begin{tabular}{|c|c|}
    \hline
    Question           & Answer                \\ \hline
    $1$                & $A$                  \\\hline
    $2$                & $B$                  \\\hline
    $3$                & $C$                  \\\hline
    $4$                & $D$                 \\\hline
    $5$                & $A$                 \\\hline
    $6$                & $B$                 \\\hline
    $7$                & $D$                 \\ \hline 
    \end{tabular}
\end{center}

\end{document}
4
  • Try add some extra row height: \setlength\extrarowheight{2pt} (for example after \beginbcenter} or if you wish in document preamble).
    – Zarko
    Sep 9, 2019 at 9:35
  • @Zarko Would you please correct my code? its my humble request.
    – SandyM
    Sep 9, 2019 at 9:43
  • Could you please explain why all the numbers and the letters anre in math mode? This is most likely not needed here.
    – leandriis
    Sep 9, 2019 at 9:50
  • @leandriis it was done by mistake.
    – SandyM
    Sep 9, 2019 at 9:53

2 Answers 2

1
\documentclass[12pt]{article}
\usepackage[a4paper,
            vmargin=1in, hmargin.7in,
            headheight=14.5pt,]{geometry}
%\usepackage[utf8]{inputenc} load by article
\usepackage[misc]{ifsym}
\usepackage{mathtools}  % load msmath
\usepackage{amssymb}    % load amsfonts
\usepackage{forest}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
\large
\begin{center}
\setlength\extrarowheight{2pt}
    \begin{tabular}{|c|c|}
    \hline
    Question           & Answer             \\ \hline
    $1$                & $A$                \\\hline
    $2$                & $B$                \\\hline
    $3$                & $C$                \\\hline
    $4$                & $D$                \\\hline
    $5$                & $A$                \\\hline
    $6$                & $B$                \\\hline
    $7$                & $D$                \\ \hline
    \end{tabular}
\end{center}
\end{document}

enter image description here

Note, if you will use in text letters as g, y, j, f, than will vertical center will optically looks different. With other words, text is now already vertical centered if you consider mentioned letters.

1

In your code you are using c as column definition which does not support line breaks. That means the rows height will not exceed one line and so vertical alignment is neglectable.

In case of using fixed column widths with p{...} which supports line breaks this issue can be solved by using the array packe and m{...} for column definition.

\documentclass[12pt]{article}
\usepackage[
a4paper,top=1in,bottom=1in,left=0.7in,right=0.7in,headheight=14.5pt,]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{array}
\begin{document}

\begin{tabular}{|m{3cm}|m{3cm}|}
    \hline
    Question           & Answer                             \\ \hline
    question           & answer answer answer answer answer \\ \hline
\end{tabular}

\end{document}

Result (top without vertical centering, bottom with vertical centering) :enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .