2

I want to put all elements of the array vertically centered. I have tried \arraystretch command to do so, but it is not working.

Code:

\documentclass[12 pt, a4paper]{book}
\usepackage{multicol}
\usepackage{geometry}
\geometry{
     a4paper,
     total={170 mm,257 mm},
     left=20 mm,
     top=20 mm,
     }
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{indentfirst}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage{color}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage{mathtools}


\setlength{\parindent}{2em}

\begin{document}

\indent \textbf{Step 2 :} \hspace{0.2 cm} Find the hexa-decimal equivalent of the integer part.
    \[
    \hspace{-2 cm}      
    \begin{array}{c|c|c}
        \renewcommand{\arraystretch}{5}
        \textbf{Radix} & \textbf{Integer} & \textbf{Remainder}\\
        \hline
         16 & 620 & \mathrm{C}\\
        \hline
         16 &  38 & 6\\
        \hline
         16 &   2 & 2\\
        \hline
            &   0 &  \\
    \end{array}
    \]
\end{document}

The output obtained from this code is as follows:

Output:

Obtained output

Can anyone help me to get the elements of array vertically centered?

0

With use of \setlength\extrarowheight{2pt} numbers will looks better vertically centered:

enter image description here

\documentclass[12 pt, a4paper]{book}
\usepackage{array}

\setlength{\parindent}{2em}

\begin{document}

\indent \textbf{Step 2 :} \hspace{0.2 cm} Find the hexa-decimal equivalent of the integer part.
    \[\setlength\extrarowheight{2pt}  % <---
    %\hspace{-2 cm}
    \begin{array}{c|c|c}
        \renewcommand{\arraystretch}{5}
        \textbf{Radix} & \textbf{Integer} & \textbf{Remainder}\\
        \hline
         16 & 620 & \mathrm{C}\\
        \hline
         16 &  38 & 6\\
        \hline
         16 &   2 & 2\\
        \hline
            &   0 &  \\
    \end{array}
    \]
\end{document}
| improve this answer | |
1

Don't play with arraystretch to vertically centre the contents of cells: it increases asymetrically the spaces at the top and at the bottom of cells. Use cellspace instead, which enables you to define minimal vertical spacings at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you load siunitx).

Unrelated: needless to load amsfonts if you load amssymb and amsmath if you load amthtools.

\documentclass[12 pt, a4paper]{book}
\usepackage{multicol}
\usepackage{geometry}
\geometry{
     a4paper,
     total={170 mm,257 mm},
     left=20 mm,
     top=20 mm,
     }
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{indentfirst}
\usepackage[utf8]{inputenc}%
%\usepackage{palatino}
\usepackage{newpxtext, newpxmath}
\usepackage{color}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage[math]{cellspace}
\setlength{\cellspacetoplimit}{6pt}
\setlength{\cellspacebottomlimit}{6pt}

\setlength{\parindent}{2em}

\begin{document}

    \[
    \hspace{-2 cm}
    \begin{array}{c|Sc|c}
        \textbf{Radix} & \textbf{Integer} & \textbf{Remainder}\\
        \hline
         16 & 620 & C\mathrm{C}\\
        \hline
         16 & 38 & 6\\
        \hline
         16 & 2 & 2\\
        \hline
            & 0 & \\
    \end{array}
    \]

\end{document}

enter image description here

| improve this answer | |

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.