표 형식 문제

표 형식 문제

LaTeX에서 다음 테이블을 다시 만드는 데 문제가 있습니다. 내가 원하는 테이블

(첫 번째 열에서 "Action"은 가운데에 있고 그 아래 행은 왼쪽 정렬됩니다.) 내가 얻은 가장 가까운 것은 다음과 같습니다.

 \documentclass[12pt,oneside,letterpaper]{book}

  \usepackage{array}
  \usepackage{multirow}

  \begin{document}

 \begin{tabular}{|l|
 >{\centering\arraybackslash}p{0.75in}|  % this centers over multiple lines
 >{\centering\arraybackslash}p{0.75in}|
 >{\centering\arraybackslash}p{1.1in}|
 >{\centering\arraybackslash}p{1.1in}|
 >{\centering\arraybackslash}p{1.1in}|}
 \hline 
 \multicolumn{1}{|c|}{Action} % Fake multicol centers action
 & \multicolumn{2}{|c|}{Magnetic Flux}  % Merge two columns
 & \multirow{2}{1.1in}{\centering Direction of \\ Induced $B$ \\ Field  (Expected)} % Multirow seems not to be working?
 & \multirow{2}{1.1in}{\centering Expected Direction of Induced Current (CW/CCW)}
 & \multirow{2}{1.1in}{\centering Actual Direction of Induced Current } \\ 
 \hline 
 & Direction (Up/Down) & Increasing/ Decreasing &&& \\ % This row isn't behaving right
 \hline
 N pole in & & & & & \\ \hline 
 N pole out & & & & & \\ \hline
 S pole in & & & & & \\ \hline 
 S pole out & & & & & \\ \hline
 \end{tabular} 
 \end{document}

이 테이블을 생성합니다. 내가 가지고 있는 테이블

여러 열에 걸쳐 작업을 확장하는 방식으로 여러 행이 제대로 작동하지 않는 것 같나요? 그리고 중앙 작업에 "가짜" 멀티콜을 사용하고 있기 때문에 여러 행으로 확장하는 데 문제가 있습니다.

어떤 도움이라도 주시면 감사하겠습니다! 감사해요!

편집: 저는 Mac에서 실행 중이고 pdfTeX 3.14159265-2.6-1.40.20(TeX Live 2019)으로 컴파일하고 있습니다. 예, 표가 표시됩니다. 사람들이 다른 테이블을 얻으면 어떤 컴파일러를 사용하여 무엇을 얻었는지 보여줄 수 있습니까? 문서 클래스와 함께 \begin{document} 및 \end{document}를 추가했습니다. 제가 컴파일하고 있는 전체 파일입니다.

.tex 및 결과 .pdf에 대한 링크: https://www.dropbox.com/s/2o92882h9q4xtt0/test.pdf?dl=0 https://www.dropbox.com/s/ho1a5mzbhjoe5oi/test.tex?dl=0

답변1

나는 당신이 다음을 찾고 있다고 가정합니다.

여기에 이미지 설명을 입력하세요

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{array, makecell, multirow}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\setcellgapes{3pt}
\makegapedcells

\begin{document}
 \begin{tabular}{|l| P{0.75in}|  
                     P{0.75in}|
                     P{1 in}|
                     P{1.2 in}|
                     P{1 in}|}
    \hline
\multirow{4}{*}{Action}
    & \multicolumn{2}{c|}{Magnetic Flux}    &   &   &   \\
    \cline{2-3}
    & \makecell{Direction\\ (Up/Down)}
        & \makecell{Increasing/\\ Decreasing}
            & \multirow{-2.8}{=}{\centering Direction of Induced $B$ Field  (Expected)}
                & \multirow{-2.8}{=}{\centering Expected Direction of Induced Current (CW/CCW)}
                    & \multirow{-2.8}{=}{\centering Actual Direction of Induced Current}   \\
 \hline
 N pole in  & & & & & \\ \hline
 N pole out & & & & & \\ \hline
 S pole in  & & & & & \\ \hline
 S pole out & & & & & \\ \hline
 \end{tabular}
 \end{document}

답변2

calstable패키지의 도움으로 조판된 두 개의 코드를 동봉했습니다.칼로리.

첫 번째 표는 수직선으로 조판되었습니다. 헤더 너비로 인해 다음의 도움으로 여백을 줄였습니다.기하학.

두 번째 행 머리글을 셀 하단에 정렬했으며 다른 모든 셀의 내용은 세로 중앙에 배치되었습니다. 또한 헤더에 사용된 글꼴 크기가 줄어들어 덜 눈에 띄고 방해가 되지 않습니다.

두 번째는 calstable수직선 없이 조판된 것입니다. 여러분이 알게 되겠지만, 이는 가독성을 위해 불필요합니다.

여기에 이미지 설명을 입력하세요

\documentclass[12pt,oneside,letterpaper]{book}
\usepackage{lmodern, cals}
\usepackage[left=3cm, right=3cm]{geometry}

% Set up the carlstable
\makeatletter
%% All rules of same weight
\def\cals@framers@width{0.4pt}   % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.4pt}
\def\cals@bodyrs@width{0.4pt}
\def\cals@AtBeginCell{\vfil}            % All cell contents vertically centred

% Shorthands for spanning cells
\let\nc=\nullcell
\let\sc=\spancontent

\def\rb{\ifx\cals@borderR\relax     % Right Border (rules) switch (off-on)
    \def\cals@borderR{0.0pt}
\else \let\cals@borderR\relax\fi}

\def\lb{\ifx\cals@borderL\relax     % Left Border switch (off-on)
    \def\cals@borderL{0.0pt}
\else \let\cals@borderL\relax\fi}

\def\bb{\ifx\cals@borderB\relax     % Bottom Border switch (off-on)
    \def\cals@borderB{0.0pt}
\else \let\cals@borderB\relax\fi}

\def\lp{\ifdim\cals@paddingL=0.0pt\relax    % Left padding switch (off-on) 
\setlength{\cals@paddingL}{3pt}
\else \setlength{\cals@paddingL}{0pt}\fi}

\def\rp{\ifdim\cals@paddingR=0.0pt\relax    % Right padding switch (off-on)
\setlength{\cals@paddingR}{3pt}
\else \setlength{\cals@paddingR}{0.0pt}\fi}
\makeatother

\begin{document}

\begin{calstable}[c]

% Defining 5 columns, 1 are for double vertical rules (col2)
\colwidths{{\dimexpr(\columnwidth/50*7+8pt)}
                   {\dimexpr(\columnwidth/50*7-5pt)}
                   {\dimexpr(\columnwidth/50*7-5pt)}
                   {\dimexpr(\columnwidth/50*9)}
                   {\dimexpr(\columnwidth/50*10+2pt)}
                   {\dimexpr(\columnwidth/50*9)}
            }
\makeatletter
\setlength{\cals@paddingL}{2pt}    % Changes to padding has to go inside the tables preamble
\setlength{\cals@paddingR}{2pt}   % Decrease tabcolsep from 4.96pt to 2pt
\setlength{\cals@paddingB}{3pt} % Uncomment if you want less space between cells
%\setlength{\cals@paddingT}{2pt}

% R1H1 
\thead{\footnotesize%
\brow
    \nc{lrt}
    \nc{ltb}
    \nc{rtb}\alignC\sc{Magnetic Flux}
    \nc{lrt}
    \nc{lrt}
    \nc{lrt}
\erow
%
%R2H2 % Header
\brow
    \nc{lrb}\alignC\sc{Action}
    \cell{\vfill Direction\\ (Up/Down)}
    \cell{\vfill Increasing/\\ Decreasing}
    \nc{lrb}\alignC\sc{\vfill Direction of\\Induced $B$\\\mbox{Field (Expected)}}
    \nc{lrb}\alignC\sc{\vfill \mbox{Expected Direction}\\\mbox{of Induced Current}\\(CW/CCW)}
    \nc{lrb}\alignC\sc{\vfill\mbox{Actual Direction}\\of Induced\\Current\vphantom{j}} % \vphantom command since Current has no depth
\erow
}
\tfoot{\lastrule\strut}
\small
%R3B1
\brow
    \alignL\cell{N pole in}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R4B2
\brow
    \alignL\cell{N pole out}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R5B3
\brow
    \alignL\cell{S pole in}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R6B4
\brow
    \alignL\cell{S pole out}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
\makeatletter
\end{calstable}\par

\vspace{1cm}

\begin{calstable}[c]

% Defining 5 columns, 1 are for double vertical rules (col2)
\colwidths{{\dimexpr(\columnwidth/50*7+8pt)}
                   {\dimexpr(\columnwidth/50*7-5pt)}
                   {\dimexpr(\columnwidth/50*7-5pt)}
                   {\dimexpr(\columnwidth/50*9)}
                   {\dimexpr(\columnwidth/50*10+2pt)}
                   {\dimexpr(\columnwidth/50*9)}
            }
\makeatletter
%% All rules of same weight
\def\cals@framers@width{0.8pt}   % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.0pt}
\def\cals@bodyrs@width{0.6pt}
\def\cals@cs@width{0.0pt}             % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.3pt}
\def\cals@AtBeginCell{\vfil}            % All cell contents vertically centred
\setlength{\cals@paddingL}{3pt}    % Changes to padding has to go inside the tables preamble
\setlength{\cals@paddingR}{3pt}   % Decrease tabcolsep from 4.96pt to 2pt
\setlength{\cals@paddingB}{3pt} % Uncomment if you want less space between cells
%\setlength{\cals@paddingT}{2pt}

% R1H1 
\thead{\footnotesize%
\brow
    \lp\nc{lrt}\lp
    \nc{ltb}
    \nc{rtb}\alignC\sc{Magnetic Flux}
    \nc{lrt}
    \nc{lrt}
    \rp\nc{lrt}\rp
\erow
%
%R2H2 % Header
\brow
    \lp\nc{lrb}\alignC\sc{Action}\lp
    \cell{\vfill Direction\\ (Up/Down)}
    \cell{\vfill Increasing/\\ Decreasing}
    \nc{lrb}\alignC\sc{\vfill Direction of\\Induced $B$\\\mbox{Field (Expected)}}
    \nc{lrb}\alignC\sc{\vfill \mbox{Expected Direction}\\\mbox{of Induced Current}\\(CW/CCW)}
    \rp\nc{lrb}\alignC\sc{\vfill\mbox{Actual Direction}\\of Induced\\Current\vphantom{j}}\rp % \vphantom command since Current has no depth
\erow
}
\tfoot{\lastrule\strut}
\small
%R3B1
\brow
    \lp\bb\alignL\cell{N pole in}\lp
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \rp\cell{}\rp
\erow
%R4B2
\brow
    \lp\alignL\cell{N pole out}\lp
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \rp\cell{}\rp
\erow
%R5B3
\brow
    \lp\alignL\cell{S pole in}\lp
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \rp\cell{}\bb\rp
\erow
%R6B4
\brow
    \lp\alignL\cell{S pole out}\lp
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \rp\cell{}\rp
\erow
\makeatletter
\end{calstable}\par
\end{document}

\end{document}

답변3

{NiceTabular}of 를 사용하면 표 형식을 쉽게 수행할 수 있습니다 nicematrix.

에서는 {NiceTabular}명령을 사용하여 가로 및 세로로 셀을 병합합니다 \Block. 행의 경우 수를 제공합니다.논리적행(와 같이 물리적 줄 수가 아님 \multicolumn).

키를 사용하면 hvlines블록(에 의해 구성됨 \Block)을 제외한 모든 규칙이 그려집니다.

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{lccccc}[hvlines,cell-space-limits=3pt]
\Block[c]{2-1}{Action} 
  & \Block{1-2}{Magnetic Flux} 
    & 
      & \Block{2-1}{Direction of\\ Induced $B$ Field\\ (Expected)}
        & \Block{2-1}{Expected Direction\\ of Induced Current\\ (CW/CCW)}
          & \Block{2-1}{Actual\\ Direction of\\ Induced Current} \\
& \Block{}{Direction\\ (Up/Down)} & \Block{}{Increasing/\\ Decreasing} \\
N pole in  \\ 
N pole out \\ 
S pole in  \\ 
S pole out \\ 
\end{NiceTabular}

\end{document}

여러 컴파일이 필요합니다( nicematrix내부적으로 PGF/Tikz 노드를 사용하기 때문에).

위 코드의 출력

관련 정보