Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm working with moderncv and having difficulties when creating a table in a narrow space. How to make the table properly?

Edited:

    \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}
share|improve this question
    
if possible set the \hintscolumnwidth a bit narrower and then play around with the column sizes. Or reformat the table. If you need to, search the side on how to change the font size for a table. Please note that you do not have to set the multirows in you your last line. Just if you have to. But do not set a width here, as this would be doubled. Just use * –  LaRiFaRi Jul 12 at 18:35

1 Answer 1

up vote 2 down vote accepted

Here is a compromise: I reduced hintscolumnwidth to 3.25cm and tabcolsep to 2.6pt. Another solution would be to keep 3.85cm for \hintscolwidth, have 4pt for \tabcolsep and use \footnotesize for the table. I used the showframe option of geometry to check if the table lies between the margins.

To simplify the code I used the makecell: it defines a \thead command that supports \\ in cells and common formatting — here \ bfseries. For two of the cells that were really too wide, I used \makecell ang split the contents of the cells into two lines — hope your specifications allow that. I also loaded booktabs to use its variable thickness for horizontal rules.

I have two ways to obtain a nice looking result: one uses the \multirowcell/\multirowthead, from the makecell package, which has a simpler syntax than the original multirow, and retains the common formatting; the other doesn't use any multirow, but the \stackon command from the stackengine package.

Finally, as I suppose the number in the first column corresponds to an enumeration I emulated this with a tabenum counter and a tabitem command (inspired by the listliketab package.

     \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} 

enter image description here

share|improve this answer
    
Sorry, I forgot to write down \cline{6-8} at the end of line 37. And I want to keep \setlength{\hintscolumnwidth}{4cm}, if still possible. –  kalakay Jul 12 at 20:46
    
@kalakay: Here are two variants, one with (almost) 4cm for \hintscolumnwidth, playing with tabcolsep. –  Bernard Jul 12 at 21:50
    
Please help me, I have a long cell content. (See the code after edited.) –  kalakay Jul 13 at 12:14
    
@kalakay: I've modified my answer, leading to 4 solutions instead of 2. I hope some two-line cells are OK –  Bernard Jul 13 at 14:55
    
Answered! Thank you, it was solved with the font size and \makecell. –  kalakay Jul 13 at 17:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.