레슨 5 / 8·20분
표와 그림
학술 문서에서 표와 그림은 데이터를 효과적으로 전달하는 핵심 요소입니다. LaTeX에서는 플로팅 환경(table, figure)을 사용하여 자동 번호 매기기, 캡션, 상호참조를 지원합니다.
플로팅 표 (table 환경)
latex
% 표를 플로팅 환경으로 감싸기
\begin{table}[htbp]
\centering
\caption{실험 결과 요약}
\label{tab:results}
\begin{tabular}{|l|c|c|c|}
\hline
모델 & 정확도 & 정밀도 & 재현율 \\
\hline
모델 A & 0.92 & 0.89 & 0.94 \\
모델 B & 0.95 & 0.93 & 0.96 \\
모델 C & 0.88 & 0.91 & 0.85 \\
\hline
\end{tabular}
\end{table}
% 위치 옵션: h(현재 위치), t(페이지 상단),
% b(페이지 하단), p(별도 페이지)booktabs로 전문적인 표 만들기
latex
\usepackage{booktabs}
\begin{table}[htbp]
\centering
\caption{알고리즘 성능 비교}
\label{tab:comparison}
\begin{tabular}{lrrr}
\toprule
알고리즘 & 시간 (ms) & 메모리 (MB) & 정확도 (\%) \\
\midrule
QuickSort & 12.3 & 2.1 & -- \\
MergeSort & 15.7 & 4.2 & -- \\
HeapSort & 14.1 & 1.8 & -- \\
\midrule
CNN & 245 & 128 & 95.2 \\
RNN & 312 & 96 & 93.8 \\
\bottomrule
\end{tabular}
\end{table}그림 삽입
latex
\usepackage{graphicx}
% 단일 그림
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{images/architecture.png}
\caption{시스템 아키텍처 다이어그램}
\label{fig:architecture}
\end{figure}
% 크기 옵션
\includegraphics[width=5cm]{image.png} % 고정 너비
\includegraphics[height=3cm]{image.png} % 고정 높이
\includegraphics[scale=0.5]{image.png} % 50% 축소
\includegraphics[width=\linewidth]{image.png} % 줄 너비에 맞춤
\includegraphics[angle=90]{image.png} % 90도 회전여러 그림 나란히 배치
latex
\usepackage{subcaption}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{images/before.png}
\caption{처리 전}
\label{fig:before}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{images/after.png}
\caption{처리 후}
\label{fig:after}
\end{subfigure}
\caption{이미지 처리 결과 비교}
\label{fig:comparison}
\end{figure}
% 참조: 그림~\ref{fig:comparison}에서 보듯이...
% 세부 그림: 그림~\ref{fig:before}(a)와 \ref{fig:after}(b)는...표와 그림 참조
latex
% 본문에서 참조하기
표~\ref{tab:results}에 실험 결과를 정리하였다.
그림~\ref{fig:architecture}은 전체 시스템 구조를 보여준다.
% 목록 자동 생성
\listoftables % 표 목록
\listoffigures % 그림 목록
% 표/그림이 원하는 위치에 배치되지 않을 때
\usepackage{float}
\begin{figure}[H] % H: 반드시 현재 위치에 배치
\centering
\includegraphics[width=0.6\textwidth]{image.png}
\caption{정확히 이 위치에 배치됨}
\end{figure}💡
booktabs 패키지를 사용하면 세로선 없이 깔끔한 학술용 표를 만들 수 있습니다. \toprule, \midrule, \bottomrule 세 가지 선만 사용하는 것이 관례입니다. 그림은 PDF, PNG, JPG 형식을 지원하며, 벡터 형식인 PDF가 가장 선명합니다.