\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}
我想水平居中对齐单元格文本。内容放在单元格的下方。如何将主题放在单元格的中心?
我试过
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{tabular}{|M{0.20cm}|p{5cm}|p{1.7cm}|p{1.5cm}|}
没有解决。
答案1
与您的 MWE(最小工作示例)相比,代码中的更改标记为% <---
:
\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}
答案2
\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}
您可以使用增加可选参数规则。文本出现在基线上。因此,对于水平对齐,您可以向下移动为\rule{0cm}{0.8cm}
命令创建的框。