我試圖將文字中心(水平或垂直)放置在乳膠表格的單元格中(請參閱最後一張圖片)。有趣的是,https://www.papeeria.com
當我使用 TeXLive 2016 發行版時,程式碼可以在線上編輯器中運行,例如 ,但在最新的發行版 2019 中則不行。我已經重新安裝了 texmaker 和 LaTeX。
我的程式碼是:
\documentclass[landscape]{article}
\usepackage{array}
\usepackage{geometry}
\geometry{a4paper, left =0.85cm, right= 0.85cm, top = 1.55cm, bottom = 1.55cm}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}
\usepackage{array} % for the first table
\usepackage{xcolor,colortbl} % <--- color cell in table
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|N}
\hline
\cellcolor{orange!50} \huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\[85mm]
\hline
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\ [85mm]
\hline
\end{tabular}
\end{table}
\newpage
\begin{table}[ht]
\centering
\begin{tabular}{|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|N}
\hline
\cellcolor{orange!50} \huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\[85mm]
\hline
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\ [85mm]
\hline
\end{tabular}
\end{table}
\end{document}
但我想要這個:
答案1
您可以使用具有定義高度的空列來偽造垂直高度。以下內容將您的 (未使用,為什麼要添加它們?)N
類型的列替換為H{85mm}
,這是一個垂直居中的列,高 85 毫米。
\documentclass[landscape]{article}
\usepackage{array}
\usepackage{geometry}
\geometry{a4paper, left =0.85cm, right= 0.85cm, top = 1.55cm, bottom = 1.55cm}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}
\newcolumntype{H}[1]{@{}>{\rule{0pt}{#1}}m{0pt}@{}}
\usepackage{array} % for the first table
\usepackage{xcolor,colortbl} % <--- color cell in table
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|H{85mm}}
\hline
\cellcolor{orange!50} \huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\
\hline
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\
\hline
\end{tabular}
\end{table}
\newpage
\begin{table}[ht]
\centering
\begin{tabular}{|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|H{85mm}}
\hline
\cellcolor{orange!50} \huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\
\hline
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\\
\hline
\end{tabular}
\end{table}
\end{document}
如果您不希望表的每一行都有這種效果,您可以切換回舊N
類型列並在其中使用明確\rule{0pt}{<height>}
設定該行的高度。
答案2
\parbox
允許您指定高度和內部對齊方式,而p{}
列及其變體則不然。您需要 collcell 套件才能使用它們。
\documentclass[landscape]{article}
\usepackage{geometry}
\geometry{a4paper, left =0.85cm, right= 0.85cm, top = 1.55cm, bottom = 1.55cm}
\usepackage{array}
\usepackage{collcell}
\usepackage{xcolor,colortbl} % <--- color cell in table
\newcommand{\mycolumn}[1]{\parbox[c][85mm][c]{\myarg}{\centering #1}}
\newcolumntype{M}[1]{>{\def\myarg{#1}\collectcell\mycolumn}{l}<{\endcollectcell}}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|M{5.1cm}|}
\hline
\cellcolor{orange!50} \huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text \\
\hline
\huge Text &
\huge Text &
\huge Text &
\huge Text &
\huge Text \\
\hline
\end{tabular}
\end{table}
\end{document}
答案3
您可以使用該tabularray
包,然後您的文字將自動垂直居中:
\documentclass[landscape]{article}
\usepackage{geometry}
\geometry{a4paper, hmargin=0.85cm, vmargin=1.55cm}
\usepackage{tabularray}
\usepackage{xcolor}
\begin{document}
\begin{table}[ht]
\centering
\begin{tblr}{
vlines,
hlines,
colspec={XXXXX},
rows={ht=8.5cm,halign=c,font=\huge},
cell{1}{1}={bg=orange!50}
}
Text & Text & Text & Text & Text\\
Text & Text & Text & Text & Text\\
\end{tblr}
\end{table}
\end{document}