我正在使用 moderncv,在狭窄的空间中创建表格时遇到困难。如何正确制作表格?
編輯:
\documentclass[10pt,a4paper,sans]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[indonesian]{babel}
\usepackage{array, booktabs}
\usepackage{multirow}
\usepackage[raggedrightboxes]{ragged2e}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\newcounter{tabenum}
\newcommand\tabitem{\refstepcounter{tabenum}\thetabenum.}
\moderncvstyle{casual}
\moderncvcolor{blue}
\usepackage{lipsum}
\usepackage[scale=0.75,margin=1.5cm]{geometry}
\firstname{}
\familyname{}
\address{}
\mobile{}
\phone{}
\fax{}
\email{}
\homepage{}
\extrainfo{}
\quote{}
\setlength{\hintscolumnwidth}{3cm}
\setlength\tabcolsep{3.25pt}
\begin{document}
\makecvtitle
\section{Riwayat Pekerjaan}
\cvline{Riwayat Kepangkatan dan Golongan Ruang Penggajian}{\small\renewcommand\arraystretch{1.2}
\setcounter{tabenum}{0}
\begin{tabular}[t]{@{}r@{\hskip\labelsep}ccclllll@{}}
\multirow{2}{*}{\thead{{No.}}} & \multirow{2}{*}{\thead{Pangkat}} & \multirow{2}{*}{\thead{Gol. Ruang}} & \multirow{2}{*}{\thead{Berlaku TMT}} & \multirow{2}{*}{\thead{Gaji Pokok}} & \multicolumn{3}{c}{\thead{Surat Keputusan}} \\\cline{6-8}
& \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & & \multicolumn{1}{c}{} & \multicolumn{1}{c}{\thead{Pejabat}} & \multicolumn{1}{c}{\thead{Nomor}} & \multicolumn{1}{c}{\thead{Tanggal}} \\
\midrule[1pt]\addlinespace
\tabitem & Pengatur & II/c (CPNS) & 1 Jan 1991 & 56.080 & Mendikbud & 4700/A2.IV.1/C/1991 & 21/01/1991 \\
\tabitem & Pengatur & II/c (PNS) & 1 Nov 1992 & 70.100 & Mendikbud & 356/B/CI/SP & 31/10/1992 \\
\tabitem & Pengatur Tingkat I & II/d & 1 Okt 1994 & 148.700 & BAKN & II.13-23/05021/KEP/X/1994 & 03/06/1996 \\
\end{tabular}}
\setcounter{tabenum}{0}
\end{document}
答案1
这是一个折衷方案:我将 缩减hintscolumnwidth
为3.25cm
并将tabcolsep
缩减为2.6pt
。另一个解决方案是保留 \hintscolwidth 的 3.85cm,将 \tabcolsep 的 4pt 用作\footnotesize
表格。我使用showframe
选项来geometry
检查表格是否位于边距之间。
为了简化代码,我使用了makecell
:它定义了一个\thead
支持\\
单元格和常见格式的命令 — 此处为 \ bfseries。对于两个确实太宽的单元格,我使用\makecell
ang 将单元格的内容拆分为两行 — 希望您的规范允许这样做。我还加载了booktabs
使用其可变厚度作为水平规则。
我有两种方法来获得漂亮的结果:一种是使用包\multirowcell/\multirowthead
中的makecell
,它的语法比原始的多行更简单,并且保留了通用格式;另一种不使用任何多行,而是使用包\stackon
中的命令stackengine
。
最后,我假设第一列中的数字对应于一个枚举,我用一个tabenum
计数器和一个tabitem
命令(受listliketab
包的启发)模拟了它。
\documentclass[10pt,a4paper, sans, showframe, nomarginpar]{moderncv}
\usepackage[T1]{fontenc}
%%\usepackage[indonesian]{babel}
\usepackage{array, booktabs}
\usepackage{multirow}
\usepackage[raggedrightboxes]{ragged2e}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadalign{cb}
\renewcommand\cellalign{lt}
\setcellgapes{3pt}
\makegapedcells
\usepackage[usestackEOL]{stackengine}
\setstackEOL{;}
\newcounter{tabenum}
\newcommand\tabitem{\refstepcounter{tabenum}\thetabenum.}
\moderncvstyle{casual}
\moderncvcolor{blue}
\usepackage{lipsum}
\usepackage[scale=0.75,margin=1.5cm]{geometry}
\firstname{}
\familyname{}
\address{}
\mobile{}
\phone{}
\fax{}
\email{}
\homepage{}
\extrainfo{}
\quote{}
\begin{document}
\makecvtitle
\section{Riwayat Pekerjaan}
\setlength{\hintscolumnwidth}{3.25cm} \setlength\tabcolsep{2.6pt}
\cvline{Riwayat Kepangkatan dan Golongan Ruang Penggajian}{\small%\
\setcounter{tabenum}{0}
\begin{tabular}[t]{@{}r@{\hskip\labelsep}ccclllll@{}}
\multirowthead{3}{No.} & \multirowthead{3}{Pangkat}& \multirowthead{3}{Gol. Ruang} & \multirowthead{3}{Berlaku TMT} & \multirowthead{3}{Gaji Pokok} & \multicolumn{3}{@{}c@{}}{\thead{Surat Keputusan}} \\\cmidrule(lr{6pt}){6-8}
& & & & & \thead{Pejabat} & \thead{Nomor} & \thead{Tanggal} \\
\cmidrule[1pt]{1-6}\cmidrule[1pt](lr{4pt}){6-8}
\tabitem & Pengatur & II/c (CPNS) & 1 Jan 1991 & 56.080 & Mendikbud & 4700/A2.IV.1/C/1991 & 21/01/1991 \\
\tabitem & Pengatur & II/c (PNS) & 1 Nov 1992 & 70.100 & Mendikbud & 356/B/CI/SP & 31/10/1992 \\
\tabitem & \makecell{Pengatur\\ Tingkat I} & II/d & 1 Okt 1994 & 148.700 & BAKN & \makecell{II.13-23/05021/\\ KEP/X/1994} & 03/06/1996 \\
\end{tabular}}\bigskip
\cvline{Riwayat Kepangkatan dan Golongan Ruang Penggajian}{\small%
\setcounter{tabenum}{0}
\begin{tabular}[t]{@{}r@{\hskip\labelsep}ccclllll@{}}\\\cmidrule(lr{6pt}){6-8}
\thead{No.} & \thead{Pangkat}& \thead{Gol. Ruang} & \thead{Berlaku TMT} & \thead{Gaji Pokok} & %
\thead{Pejabat} & \thead{\smash{\stackon[4ex]{Nomor}{Surat Keputusan}}} & \thead{Tanggal} \\
\cmidrule[1pt]{1-6}\cmidrule[1pt](lr{4pt}){6-8}
\tabitem & Pengatur & II/c (CPNS) & 1 Jan 1991 & 56.080 & Mendikbud & 4700/A2.IV.1/C/1991 & 21/01/1991 \\
\tabitem & Pengatur & II/c (PNS) & 1 Nov 1992 & 70.100 & Mendikbud & 356/B/CI/SP & 31/10/1992 \\
\tabitem & \makecell{Pengatur\\ Tingkat I} & II/d & 1 Okt 1994 & 148.700 & BAKN & \makecell{II.13-23/05021/\\ KEP/X/1994} & 03/06/1996 \\
\end{tabular}}\vspace{1cm}
\setlength{\hintscolumnwidth}{3.85cm} \setlength\tabcolsep{4pt}
\cvline{Riwayat Kepangkatan dan Golongan Ruang Penggajian}{\footnotesize%
\setcounter{tabenum}{0}
\begin{tabular}[t]{@{}r@{\hskip\labelsep}ccclllll@{}}
\multirowthead{3}{No.} & \multirowthead{3}{Pangkat}& \multirowthead{3}{Gol. Ruang} & \multirowthead{3}{Berlaku TMT} & \multirowthead{3}{Gaji Pokok} & \multicolumn{3}{@{}c@{}}{\thead{Surat Keputusan}} \\\cmidrule(lr{0.8em}){6-8}
& & & & & \thead{Pejabat} & \thead{Nomor} & \thead{Tanggal} \\
\cmidrule[1pt]{1-6}\cmidrule[1pt](lr{4pt}){6-8}
\tabitem & Pengatur & II/c (CPNS) & 1 Jan 1991 & 56.080 & Mendikbud & 4700/A2.IV.1/C/1991 & 21/01/1991 \\
\tabitem & Pengatur & II/c (PNS) & 1 Nov 1992 & 70.100 & Mendikbud & 356/B/CI/SP & 31/10/1992 \\
\tabitem & \makecell{Pengatur\\ Tingkat I} & II/d & 1 Okt 1994 & 148.700 & BAKN & \makecell{II.13-23/05021/\\ KEP/X/1994} & 03/06/1996 \\
\end{tabular}}
\cvline{Riwayat Kepangkatan dan Golongan Ruang Penggajian}{\footnotesize%
\setcounter{tabenum}{0}
\begin{tabular}[t]{@{}r@{\hskip\labelsep}ccclllll@{}}\\\cmidrule(lr{6pt}){6-8}
\thead{No.} & \thead{Pangkat}& \thead{Gol. Ruang} & \thead{Berlaku TMT} & \thead{Gaji Pokok} & %
\thead{Pejabat} & \thead{\smash{\stackon[4ex]{Nomor}{Surat Keputusan}}} & \thead{Tanggal} \\
\cmidrule[1pt]{1-6}\cmidrule[1pt](lr{0.8em}){6-8}
\tabitem & Pengatur & II/c (CPNS) & 1 Jan 1991 & 56.080 & Mendikbud & 4700/A2.IV.1/C/1991 & 21/01/1991 \\
\tabitem & Pengatur & II/c (PNS) & 1 Nov 1992 & 70.100 & Mendikbud & 356/B/CI/SP & 31/10/1992 \\
\tabitem & \makecell{Pengatur\\ Tingkat I} & II/d & 1 Okt 1994 & 148.700 & BAKN & \makecell{II.13-23/05021/\\ KEP/X/1994} & 03/06/1996 \\
\end{tabular}}\bigskip
\end{document}