매크로(newcommand) 왜 일부 텍스트가 출력되지 않습니까?

매크로(newcommand) 왜 일부 텍스트가 출력되지 않습니까?

같은 페이지에 일부 텍스트와 표를 반복하고 싶습니다. 아래에 제공된 코드를 시도하고 있지만 한 번만 인쇄되고 마지막에는 눈금자가 인쇄되지 않습니다. 전체 코드는 아래와 같습니다.

\documentclass{article}
\usepackage{multirow}
\usepackage{caption}
\usepackage{subfig}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{tabu}
\usepackage{array}
\usepackage{graphicx}
\usepackage[showframe]{geometry}
\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\captionsetup{skip=0pt}

\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{xparse}% http://ctan.org/pkg/xparse

% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\usepackage{geometry}
 \geometry{
 a4paper,
 total={210mm,297mm},
 left=5mm,
 right=5mm,
 top=2cm,
 bottom=5mm,
 }

\usetikzlibrary{arrows}
\usetikzlibrary{shapes}

\NewDocumentCommand{\myrule}{O{1pt} O{3pt} O{black}}{%
  \par\nobreak % don't break a page here
  \kern\the\prevdepth % don't take into account the depth of the preceding line
  \kern#2 % space before the rule
  {\color{#3}\hrule height #1 width\hsize} % the rule
  \kern#2 % space after the rule
  \nointerlineskip % no additional space after the rule
}

\newcommand\textbox[1]{%
  \parbox{1\textwidth}{#1}%
}

\newcommand\insertBigText[1]{
 \noindent\textbox{\hfil \Large{\textbf{#1}}\hfil} \\

\myrule[1pt][2pt]
\vspace{5pt}
\vspace*{-\baselineskip}

\begin{table}[!htbp]
\parbox{0.45\linewidth}{
  \begin{tabu} spread 0pt {|*{2}{[2pt]X[c,m]|}}
     \hline
     \multicolumn{1}{l}{\textbf{text 1}} & \vspace{5mm}\\ \hline
     \multicolumn{1}{l}{\textbf{text 2}} &  \vspace{5mm} \\\hline 
     \multicolumn{1}{l}{\textbf{text 3 }} &  \vspace{5mm}\\\hline
     \multicolumn{1}{l}{\textbf{text 4}} & some more text\\\hline

    \end{tabu}}
\hfill
\parbox{0.45\linewidth}{
\centering
  \begin{tabu} spread 0pt {|*{1}{[2pt]X[c,m]|}}
     \textbf{string 1} \\\hline 
     \textbf{string 2} \\\hline 
      string 3 \\\hline
    \end{tabu}}
\end{table}

\myrule[1pt][2pt] % strange! doesn't get printed at all
} %end \newcommand\insertBigText[1]{

% ------------ document start
\begin{document}
\captionsetup[table]{skip=0pt}  
\insertBigText{receipt} % only this part gets printed
\vspace{2mm}
\noindent\textbox{\hfil \Large{\textbf{counterfoil}}\hfil} \\ % strange! doesn't get printed at all
\myrule[1pt][2pt] % strange! doesn't get printed at all
\insertBigText{counterfoil} % strange! doesn't get printed at all


\end{document}

답변1

여기서 가장 큰 문제는 라인에 있습니다.

\kern\the\prevdepth % don't take into account the depth of the preceding line

의 정의에 있습니다 \myrule. 문제를 이해하려면 무엇을 살펴보세요.TeXbook(79페이지 하단의 이중 위험 굴곡)은 다음과 같이 말합니다 \prevdepth.

그러나 수직 목록의 시작 부분이나 규칙 상자 바로 뒤에 \prevdepth센티널 값으로 설정됩니다 . −1000pt이는 다음 인터라인 접착제를 억제하는 역할을 합니다.

따라서 두 번째로 명령을 사용할 때는 자료를 조판하기 전에 (대략 !) 수직 건너뛰기를 수행합니다 \prevdepth. 자료는 분명히 페이지 밖으로 위쪽으로 밀려 나옵니다.-1000pt-1000pt-14in

\\이 외에도 빈 줄을 사용하거나 \Large인수가 있는 명령으로 사용하는 등 코드에 다른 문제가 있습니다 . 문제를 해결했습니다(그러나 실제 의도에 따라 조정이 필요할 수도 있습니다).

다음은 코드의 축소 버전입니다.

\documentclass{article}
\usepackage{tabu}
\usepackage[showframe]{geometry}

\usepackage{xparse}% http://ctan.org/pkg/xparse

\usepackage{geometry}
\geometry{
 a4paper,
 total={210mm,297mm},
 left=5mm,
 right=5mm,
 top=2cm,
 bottom=5mm,
 }

\NewDocumentCommand{\myrule}{O{1pt} O{3pt} O{black}}{%
  \par\nobreak % don't break a page here%
  \kern#2 % space before the rule
  {\color{#3}\hrule height #1 width\hsize} % the rule
  \kern#2 % space after the rule
  \nointerlineskip % no additional space after the rule
}

\newcommand\textbox[1]{%
  \parbox{1\textwidth}{#1}%
}

\newcommand\insertBigText[1]{
\noindent\textbox{\hfil{\Large\textbf{#1}}\hfil}\par
\myrule[1pt][2pt]
\vspace{5pt}
\vspace*{-\baselineskip}
\begin{table}[!htbp]
\parbox{0.45\linewidth}{%
  \begin{tabu} spread 0pt {|*{2}{[2pt]X[c,m]|}}
     \hline
     \multicolumn{1}{l}{\textbf{text 1}} & \vspace{5mm}\\ \hline
     \multicolumn{1}{l}{\textbf{text 2}} &  \vspace{5mm} \\\hline 
     \multicolumn{1}{l}{\textbf{text 3 }} &  \vspace{5mm}\\\hline
     \multicolumn{1}{l}{\textbf{text 4}} & some more text\\\hline
    \end{tabu}}
\hfill
\parbox{0.45\linewidth}{%
\centering
  \begin{tabu} spread 0pt {|*{1}{[2pt]X[c,m]|}}
     \textbf{string 1} \\\hline 
     \textbf{string 2} \\\hline 
      string 3 \\\hline
    \end{tabu}}
\end{table}
\myrule[1pt][2pt]%
}

\begin{document}

\insertBigText{receipt}
\vspace{2mm}
\myrule[1pt][2pt]
\insertBigText{counterfoil}

\end{document}

출력:

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

다음에서 여전히 두 가지 경고가 표시됩니다 geometry.

Package geometry Warning: Over-specification in `h'-direction. `width'
(597.50787pt) is ignored.

Package geometry Warning: Over-specification in `v'-direction. `height' 
(845.04684pt) is ignored.

따라서 사용된 설정을 확인해야 합니다.

업데이트

처럼egreg통지his comment조건부 테스트를 사용하여 \kern정의에 안전하게 포함할 수 있습니다.

\NewDocumentCommand{\myrule}{O{1pt} O{3pt} O{black}}{%
  \par\nobreak % don't break a page here%
  \ifdim\prevdepth>-1000pt\kern\prevdepth\fi
  \kern#2 % space before the rule
  {\color{#3}\hrule height #1 width\hsize} % the rule
  \kern#2 % space after the rule
  \nointerlineskip % no additional space after the rule
}

관련 정보