0
\documentclass[12pt]{article}
\usepackage{forloop}
\usepackage{booktabs}
\usepackage{dingbat, multido, array}
\usepackage[a4paper, left=0.1cm, right=0cm, top=0.1cm, bottom=0.1cm]{geometry}
\newcommand{\aline}{\\\hline \arabic{theyflines} & Md. &&\rule{0cm}{0.8cm}}
\begin{document}
\pagenumbering{gobble}
\newcounter{theyflines}
\multido{}{2}
{
\noindent
\begin{minipage}{0.45\textwidth}
\begin{tabular}{|p{0.20cm}|p{5cm}|p{1.7cm}|p{1.5cm}|}
\hline
SL & Name & Room No & Intention\\
\forloop{theyflines}{1}{\value{theyflines} < 30}{\aline}\\
\hline
\end{tabular}
\end{minipage}
\hspace{1cm}
}
\end{document}

enter image description here

I want to horizontally center align the cell text. The content is put on the down side of the cell. How can I put theme to center of the cell?

I tried

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{tabular}{|M{0.20cm}|p{5cm}|p{1.7cm}|p{1.5cm}|}

not solved.

5
  • 1
    you are forcing extra height but no extra depth with \rule{0cm}{0.8cm} so the baseline is lower in the cell than usual. You can use the optional argument of \rule to give extra depth as well. The table would look odd if you really vertically centred so that the baselines of digits did not match the baseline of text unless the letters used were exactly same height as the digits. Mar 4, 2020 at 9:56
  • @DavidCarlisle yes, this solve the problem. Thanks
    – alhelal
    Mar 4, 2020 at 10:10
  • @DavidCarlisle You can write this as answer.
    – alhelal
    Mar 4, 2020 at 10:12
  • @DavidCarlisle I post a answer based on your comment. If you post this as a answer I will delete my answer, because this answer actually yours.
    – alhelal
    Mar 4, 2020 at 10:18
  • 1
    No feel free to accept your answer I am not that desperate for the green tick:-) Mar 4, 2020 at 10:27

2 Answers 2

1

Changes in comparison to your MWE (Minimal Workking Example) are in code marked by % <---:

\documentclass[12pt]{article}
\usepackage[a4paper,margin=1pt]{geometry} % <---
\usepackage{forloop}
\usepackage{booktabs, tabularx}
\usepackage{multido}  % <---
\newcommand{\aline}{\\\hline\arabic{theyflines} & Md. & &  } % <---

\begin{document}
\pagenumbering{gobble}
\newcounter{theyflines}
\multido{}{2}
{
\centering
\renewcommand\arraystretch{1.5}
\begin{tabularx}{0.45\linewidth}{|p{1em}|X|c|c|}
    \hline
SL & Name & Room No & Intention 
\forloop{theyflines}{1}{\value{theyflines} < 29}{\aline}\\
    \hline
\end{tabularx}
\hfill  % <---
}
\end{document}

enter image description here

0
\documentclass[12pt]{article}
\usepackage{forloop}
\usepackage{booktabs}
\usepackage{dingbat, multido, array}
\usepackage[a4paper, left=0.1cm, right=0cm, top=0.1cm, bottom=0.1cm]{geometry}
\newcommand{\aline}{\\\hline \arabic{theyflines} & Md. &&\rule[-0.25cm]{0cm}{0.8cm}}
\begin{document}
\pagenumbering{gobble}
\newcounter{theyflines}
\multido{}{2}
{
\noindent
\begin{minipage}{0.45\textwidth}
\begin{tabular}{|p{0.20cm}|p{5cm}|p{1.7cm}|p{1.5cm}|}
\hline
SL & Name & Room No & Intention\\
\forloop{theyflines}{1}{\value{theyflines} < 30}{\aline}\\
\hline
\end{tabular}
\end{minipage}
\hspace{1cm}
}
\end{document}

You can use a raise optional parameter of rule. The text appeared on the baseline. So, for horizontal alignment you can down the box created for the \rule{0cm}{0.8cm} command.

enter image description here

You must log in to answer this question.

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