
我想在同一頁上重複一些文字和表格。我正在嘗試下面給出的程式碼,但它只列印一次,然後又不會在最後列印標尺。完整的程式碼如下。
\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
。要了解問題,請看什麼教材(第 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.
因此您需要檢查所使用的設定。
更新
作為艾格雷格中的通知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
}