1. Text line break

1) parbox

  • \parbox[position]{width}{text}

2) makecell

  • \usepackage{makecell}
  • \makecell[vertical or horizontal alignment]{text}
  • \makecell*[vertical or horizontal alignment]{text}
    *를 추가하면 위 아래에 space가 추가된다.
\begin{table}[H]
	\centering
	\begin{tabular}{|l|l|}
	\hline
	none      & very very long text\\ \hline
	parbox    & \parbox[t]{4cm}{vertical align, top\\ very very long text}\\ \hline
	parbox    & \parbox[c]{4cm}{vertical align, center\\ very very long text}\\ \hline
	parbox    & \parbox[b]{4cm}{vertical align, bottom\\ very very long text}\\ \hline
	makecell  & \makecell[l]{horizontal align, left\\ very very long text}\\ \hline
	makecell  & \makecell[c]{horizontal align, center\\ very very long text}\\ \hline
	makecell  & \makecell[r]{horizontal align, right\\ very very long text}\\ \hline
	makecell* & \makecell*[r]{horizontal align, right\\ very very long text}\\ 
	\hline
	\end{tabular}
\end{table}

3) thead

  • \usepackage{makecell}
  • thead{text} : table의 head를 설정할 때 주로 활용한다.
  • font, space, align 등을 설정할 수 있다.
set 설명
font \renewcommand{\theadfont}{fonttype}, fontsize, fontshape, fontcolor
space \renewcommand{\theadset}{\renewcommand{\arraystretch}{num}}, 1(default)
align \renewcommand{\theadalign}{align}, c(default), l(left), r(right)
\begin{table}[H]
	\centering
	\begin{tabular}{|l|l|}
	\hline
	thead	  & \thead{thead center(default),\\ very very long text}\\ 
	\hline
	\end{tabular}
	\renewcommand{\theadalign}{l}
	\begin{tabular}{|l|l|}
	\hline
	thead	  & \thead{thead align left,\\ very very long text}\\ 
	\hline
	\end{tabular}
	\renewcommand{\theadalign}{r}
	\begin{tabular}{|l|l|}
	\hline
	thead	  & \thead{thead align right,\\ very very long text}\\ 
	\hline
	\end{tabular}
\end{table}
\begin{table}[H]
	\centering
	\renewcommand{\theadfont}{\Large\bfseries\color{red}}
	\begin{tabular}{|l|l|}
	\hline
	thead	  & \thead{theadfont large,\\ very very long text}\\ 
	\hline
	\end{tabular}
\end{table}
\begin{table}[H]
	\centering
	\renewcommand{\theadset}{\renewcommand{\arraystretch}{1.5}}
	\begin{tabular}{|l|l|}
	\hline
	thead	  & \thead{thead stretch 1.5,\\ very very long text}\\ 
	\hline
	\end{tabular}
\end{table}

2. Multicolumn, Multirow

1) Multicol

  • \usepackage{multirow}
  • \multicol{num}{column align}{text}
    • num: the number of columns
    • column align: c(center) / l(left) / r(right)
      |를 통해 vertical line도 설정할 수 있다.

2) Multirow

  • \multirow[pos]{num}{width}{text}
    • pos: vertical position, t(top) / c(center,default) / b(bottom)
    • num: the number of rows
    • width: text width, table의 길이를 유지하기 위해 대부분 *를 사용한다.

3) Both multicolumn and multirow

  • \multicolumn{num}{column align}{\multirow[pos]{num}{width}{text}}
  • 예를 들어 2행 2열을 병합한다면, 2행 모두 \multicolumn command가 삽입되어야 한다.
\begin{table}[H]
	\centering
	\begin{tabular}{|c|c|c|}
	\hline
	\multicolumn{3}{|c|}{multicol}\\ \hline
	col1                            & col2 & col3\\ \hline
	\multirow{2}{*}{multirow}       & row1 & row1\\ \cline{2-3}
	                                & row2 & row2\\ \hline
	\multirow[t]{2}{*}{multirow}    & row3 & row3\\ \cline{2-3}
	                                & row4 & row4\\ \hline
	\multirow[b]{2}{*}{multirow}    & row5 & row5\\ \cline{2-3}
	                                & row6 & row6\\ \hline
	row7                            & \multicolumn{2}{c|}{\multirow{2}{*}{multicolumn, multirow}}\\ \cline{1-1}
	row8                            & \multicolumn{2}{c|}{} \\ 
	\hline
	\end{tabular}
\end{table}

3. Color

  • \usepackage{colortbl}
  • 예시를 위해 \definecolor를 이용하여 color를 지정하였다.
\usepackage[table]{xcolor}
\definecolor{myorange}{HTML}{F9C07D}
\definecolor{myblue}{HTML}{9EE0FD}
\definecolor{mygreen}{HTML}{BBFD9E}
\definecolor{mypink}{HTML}{FBBAB9}

1) cell color

  • \cellcolor{color}{text}
\begin{table}[H]
	\centering
	\begin{tabular}{|c|c|c|}
	\hline
	\cellcolor{mygreen}{col1}   & col2                      & col3\\ 
	row1                        & \cellcolor{mygreen}{row1} & row1\\ 
	row2                        & row2                      & \cellcolor{mygreen}{row2}\\
	\hline
	\end{tabular}
\end{table}

2) columns color

  • \columncolor{color}[left overhang][right overhang]
  • overhang을 지정해서 column간의 color 여백을 조정할 수 있다.
\begin{table}[H]
	\centering
	\begin{tabular}{|>{\columncolor{myorange}[0mm][2mm]}l
		|>{\columncolor{myorange}[0.5\tabcolsep]}c
		|>{\columncolor{myorange}}c|}
	\hline
	col1 & col2 & col3\\ 
	row1 & row1 & row1\\ 
	row2 & row2 & row2\\
	\hline
	\end{tabular}
\end{table}

3) row color

  • \rowcolors{start num}{color1}{color2}
    start num행부터 color1과 color2를 번갈아가면서 rowcolor를 지정할 수 있다.
    • \usepackage[table]{xcolor}, table option이 꼭 필요하다.
  • \rowcolor{color}
    개별 행마다의 color를 지정할 수 있다.
\begin{table}[H]
	\centering
	\rowcolors{1}{myorange}{myblue}
	\begin{tabular}{|c|c|c|}
	\hline
	col1 & col2 & col3\\ 
	row1 & row1 & row1\\ 
	\hiderowcolors
	row2 & row2 & row2\\ 
	\showrowcolors
	row3 & row3 & row3\\ 
	\rowcolor{mypink}
	row4 & row4 & row4\\
	\hline
	\end{tabular}	
\end{table}

4) line color

  • \arrayrulecolor{color}
    전체의 line에 대해 color를 적용한다.
  • !{\color{color}\vrule width 1pt}
    원하는 column line에 color를 적용한다.
  • \noalign{\color{color}\hrule height 1pt} :
    원하는 row line에 color를 적용한다.
\begin{table}[H]
	\centering
	\setlength\arrayrulewidth{2pt}
	\arrayrulecolor{black}
	\begin{tabular}{|c!{\color{red}\vrule width 2pt}c|c|}
	\hline
	col1 & col2 & col3\\ \noalign{\color{red} \hrule height 2pt}
	row1 & row1 & row1\\ \hline
	row2 & row2 & row2\\ 
	\hline		
	\end{tabular}
\end{table}

4. Macro

  • \newcolumntype{name}[num]{column settings}
\begin{table}[H]
	\centering 
	\newcolumntype{N}{>{\bfseries}p{1cm}}
	\newcolumntype{M}{>{\centering\itshape\small}p{2cm}}
	\newcolumntype{L}{>{\raggedleft\columncolor{mypink}\arraybackslash}p{3cm}}
	\begin{tabular}{|N|M|L|}
	\hline
	col1 & col2 & col3\\ \hline
	row1 & row1 & row1\\ \hline
	row2 & row2 & row2\\ 
	\hline
	\end{tabular}
\end{table}

댓글남기기