ข้อความกึ่งกลางแนวตั้ง multirow (2)
MWE:
\documentclass{standalone}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{tabular}{@{}l|llll@{}}
\toprule
\multicolumn{1}{c|}{\multirow{2}{*}{Test}} & \multicolumn{4}{c}{A} \\ \cmidrule(l){2-5}
\multicolumn{1}{c|}{} & 1 & 2 & 3 & 4 \\ \midrule
& & & & \\
& & & & \\ \bottomrule
\end{tabular}
\end{document}
เอาท์พุต:
Saw นี้ , นี้ บางแห่งฉันต้องใช้makecell
หรือm
แต่ไม่สามารถเข้าใจได้ ความช่วยเหลือใด ๆ ในการจัดแนว "ทดสอบ" ในแนวตั้ง
คำตอบ
นี่คือสิ่งที่คุณสามารถทำได้ด้วย{NiceTabular}
ของnicematrix
(กับรุ่นล่าสุด: 5.4 ของ 2020/10/06)
\documentclass{article}
\usepackage{booktabs}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{@{}l|llll@{}}
\toprule
\Block{2-1}{Test} & \Block{1-4}{A} \\ \cmidrule(l){2-5}
& 1 & 2 & 3 & 4 \\ \midrule
& & & & \\
& & & & \\ \bottomrule
\end{NiceTabular}
\end{document}
ใน
{NiceTabular}
คุณใช้\Block
เพื่อผสานเซลล์ทั้งในแนวตั้งและแนวนอนเนื้อหาของบล็อกประกอบด้วยที่กึ่งกลางทางคณิตศาสตร์ของสี่เหลี่ยมผืนผ้าของเซลล์ที่ผสาน (ไม่ใช่เช่นเดียวกับ
\multirow
)กฎแนวตั้งจะไม่ถูกทำลายดังนั้นจึงเข้ากันได้กับ
booktabs
(แต่คุณต้องตระหนักว่าการใช้กฎแนวตั้งไม่ได้อยู่ในจิตวิญญาณbooktabs
เลย)คุณต้องมีการคอมไพล์หลายรายการ (เนื่องจาก
nicematrix
ใช้โหนด PGF / Tikz)
หลีกเลี่ยงแนวดิ่งเพื่อผลกระทบที่ดีขึ้นและแก้ไขปัญหาช่องว่าง
\multirow
ตัวเลือกที่สามารถเปลี่ยนเป็นค่าทศนิยมสำหรับปลีกย่อยขึ้นลงปรับ / กลาง - ที่นี่เปลี่ยนเป็นค่า 2.4
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{table}[]
\begin{tabular}{@{}lllll@{}} \toprule
\multirow{2.4}{*}{Test} & \multicolumn{4}{c}{A} \\ \cmidrule(l){2-5}
& 1 & 2 & 3 & 4 \\ \midrule
& X & Y & Z & A \\
& P & Q & R & S \\ \bottomrule
\end{tabular}
\end{table}
\end{document}