
첫 번째 행에만 열 선을 사용하여 표를 그리는 방법은 무엇입니까? 내 코드의 MWE는 다음과 같습니다.
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[H]
\centering
\caption{Data of subways in Fortal city}
\rowcolors{1}{gray!20}{white}
\begin{tabular}{c|c|c|c}
\hline
Line & Extension & Stations & Vehicle type \\
\hline
South & 24,1 km & 19 & Electric \\
West & 19,5 km & 10 & VLT a diesel \\
Parangaba-Mucuripe & 13,2 km & 10 & VLT a diesel \\
East & 7,3 km & 11 & VLT a diesel \\
\hline
\end{tabular}
\end{table}
\end{document}
내가 달성하고 싶은 것:
답변1
내 문서에서 열을 제거했지만 다음을 tabular
사용하여 헤더에만 다시 그렸습니다.multicolumn{1}{c|}{text}
전체 작업 코드는 다음과 같습니다.
\documentclass[12pt,a4paper]{article}
\usepackage{float}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[H]
\centering
\caption{Data of subways in Fortal city}
\rowcolors{1}{gray!20}{white}
\begin{tabular}{cccc}
\hline
\multicolumn{1}{c|}{Line} & \multicolumn{1}{c|}{Extension} & \multicolumn{1}{c|}{Stations} & Vehicle type \\
\hline
South & 24,1 km & 19 & Electric \\
West & 19,5 km & 10 & VLT a diesel \\
Parangaba-Mucuripe & 13,2 km & 10 & VLT a diesel \\
East & 7,3 km & 11 & VLT a diesel \\
\hline
\end{tabular}
\end{table}
\end{document}
c|
이 특정 문제의 경우 마지막 열에 열을 그릴 필요가 없다는 점에 유의하세요 . 그렇지 않으면 국경으로 변해버리고 싶지 않습니다.
게다가, 항상 쓰는 것을 피하기 위해 고정된 값을 쓸 필요가 없도록 새 multicolumn{1}{c|}{text}
명령을 정의했습니다 . 그래서 개선된 코드는 다음과 같이 나타났습니다.\topr{}
\newcommand{\topr}[1]{\multicolumn{1}{c|}{#1}}
\documentclass[12pt,a4paper]{article}
\usepackage{float}
\usepackage[table]{xcolor}
\newcommand{\topr}[1]{\multicolumn{1}{c|}{#1}}
\begin{document}
\begin{table}[H]
\centering
\caption{Data of subways in Fortal city}
\rowcolors{1}{gray!20}{white}
\begin{tabular}{cccc}
\hline
\topr{Line} & \topr{Extension} & \topr{Stations} & Vehicle type \\
\hline
South & 24,1 km & 19 & Electric \\
West & 19,5 km & 10 & VLT a diesel \\
Parangaba-Mucuripe & 13,2 km & 10 & VLT a diesel \\
East & 7,3 km & 11 & VLT a diesel \\
\hline
\end{tabular}
\end{table}
\end{document}
답변2
안정된
패키지를 사용하여 설정된 테이블 유형은 다음과 같습니다.칼로리. 보시다시피 모든 규칙이 표시되며 규칙과 색상 사이에 흰색 선이 없습니다. 그러나 나는 booktable
수직선과 회색 음영이 없는 고전적인 표 형식을 조판하는 것을 권장합니다. 아래를 참조하십시오.
코딩을 줄이기 위해 몇 가지 단축키를 정의했습니다.
원본과 비교하여 측면 베어링(첫 번째 열의 왼쪽 패딩과 마지막 열의 오른쪽 패딩)을 제거했습니다. 이는 학술 테이블의 관례입니다. 또한 열을 그림과 함께 오른쪽 정렬했지만 그림을 다음으로 이동했습니다. 열의 중심을 1.25em만큼 늘렸습니다. 또한 "km"를 열 머리글로 이동했습니다. 한 줄 머리글을 선호하는 경우 열을 pt
.
\documentclass[12pt, a4paper]{article}
\usepackage{cals, url}
\usepackage{xcolor, caption}
\newcommand{\rl}{\hspace*{1.25em}}
\begin{document}
\begin{table*}
\caption{Data of subways in Fortal city}
%\footnotesize % Not necessary with too tiny font. Eventually, use `small` if you prefer smaller font in the tables.
\small\sffamily
\begin{calstable}[c]
% Defining columns relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth)/3\relax}
{\dimexpr(\columnwidth)/6\relax}
{\dimexpr(\columnwidth)/6\relax}
{\dimexpr(\columnwidth)/4\relax}
}
% The tabular fills the text area if the divisors for all columns were 4
% Set up the tabular
\makeatletter
\def\cals@framers@width{0.8pt} % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0pt}
\def\cals@bodyrs@width{0.6pt}
\def\cals@cs@width{0.4pt} % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.4pt}
\def\cals@bgcolor{}
\def\lb{\ifx\cals@borderL\relax % Left border switch (off-on)
\def\cals@borderL{0pt}
\else \let\cals@borderL\relax\fi}
\def\rb{\ifx\cals@borderR\relax % Right border switch (off-on)
\def\cals@borderR{0pt}
\else \let\cals@borderR\relax\fi}
\def\bb{\ifx\cals@borderB\relax % Bottom border switch (off-on)
\def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}
\def\lp{\ifdim\cals@paddingL=0.0pt\relax % Left padding switch (off-on)
\cals@setpadding{Ag}
\else \setlength{\cals@paddingL}{0pt}\fi}
\def\rp{\ifdim\cals@paddingR=0.0pt\relax % Right padding switch (off-on)
\cals@setpadding{Ag}
\else \setlength{\cals@paddingR}{0pt}\fi}
\def\gray{\ifx\cals@bgcolor\empty % "Switch" to turn on and off colour
\def\cals@bgcolor{gray!20}
\else \def\cals@bgcolor{} \fi}
% R1H1
\thead{\bfseries%
\brow
\gray\lp\alignL\cell{\vfil Line}\lp
\alignC\cell{\vfil Extension (km)}
\alignC\cell{\vfil Stations}
\rp\alignR\cell{\vfil Vehicle type}\rp \gray
\erow
\mdseries%
}
\tfoot{\lastrule\strut}
%R2H1
\brow
\lb\lp\bb\alignL\cell{South}\lp
\alignR\cell{24,1\rl}
\alignR\cell{19\rl}
\rp\alignR\cell{Electric}\rp
\erow
%R3H2
\brow
\gray\lp\alignL\cell{West}\lp
\alignR\cell{19,5\rl}
\alignR\cell{10\rl}
\rp\alignR\cell{VLT a diesel}\rp\gray
\erow
%R4B3
\brow
\lp\alignL\cell{Parangaba-Mucuripe}\lp
\alignR\cell{13,2\rl}
\alignR\cell{10\rl}
\rp\alignR\cell{VLT a diesel}\rp\bb
\erow
%R7N1
\brow
\gray\lp\cell{ East}\lp
\alignR\cell{7,3\rl}
\alignR\cell{11\rl}
\rp\alignR\cell{VLT a diesel}\gray\rp
\erow
\makeatletter
\end{calstable}\par
\end{table*}
\end{document}
고전적인 북테이블 스타일의 표
여기에서는 @Levy의 코드를 수정했지만 몇 가지 사항을 변경했습니다.
\documentclass[12pt,a4paper]{article}
\usepackage{booktabs, caption, tabulary}
\begin{document}
\begin{table}[!tb]
\small\sffamily\centering
\caption{Data of subways in Fortal city}
\begin{tabulary}{\linewidth}{@{}LRRC@{}}
\toprule
\textsc{line} & \textsc{extension\linebreak(km)} & \textsc{stations} & \textsc{vehicle type}\\
\midrule
South & 24,1 & 19 & Electric \\
West & 19,5 & 10 & VLT a diesel \\
Parangaba-Mucuripe & 13,2 & 10 & VLT a diesel \\
East & 7,3 & 11 & VLT a diesel \\
\bottomrule
\end{tabulary}
\end{table}
\end{document}
답변3
{NiceTabular}
of 를 사용하면 수직선을 더 이상 그리지 않겠다는 nicematrix
지시만 넣으면 됩니다 .\Block{*-*}{}
\documentclass[12pt,a4paper]{article}
\usepackage{float}
\usepackage{nicematrix}
\begin{document}
\begin{table}[H]
\centering
\caption{Data of subways in Fortal city}
\begin{NiceTabular}{c|c|c|c}
\CodeBefore
\rowcolors{1}{gray!20}{}
\Body
\hline
Line & Extension & Stations & Vehicle type \\
\hline
\Block{*-*}{}
South & 24,1 km & 19 & Electric \\
West & 19,5 km & 10 & VLT a diesel \\
Parangaba-Mucuripe & 13,2 km & 10 & VLT a diesel \\
East & 7,3 km & 11 & VLT a diesel \\
\hline
\end{NiceTabular}
\end{table}
\end{document}