%20%C2%BFPor%20qu%C3%A9%20no%20aparece%20algo%20de%20texto%20en%20la%20salida%3F.png)
Quiero repetir algunos textos y tablas en la misma página. Estoy probando el código que se proporciona a continuación, pero se imprime solo una vez y luego no se imprime la regla al final. El código completo se proporciona a continuación.
\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}
Respuesta1
El principal problema aquí es con la línea.
\kern\the\prevdepth % don't take into account the depth of the preceding line
en la definición de \myrule
. Para entender el problema, mire lo queEl libro de texto(doble curva peligrosa al final de la página 79) dice sobre \prevdepth
:
Sin embargo,
\prevdepth
se establece en el valor centinela−1000pt
al principio de una lista vertical o justo después de un cuadro de regla; esto sirve para suprimir el siguiente pegamento entre líneas.
Entonces, la segunda vez que usas tu comando, \prevdepth
es -1000pt
y haces un salto vertical de -1000pt
(¡aproximadamente -14in
!) antes de componer el material; el material, obviamente, es empujado hacia arriba, fuera de la página.
Además de esto, existen otros problemas con el código, como el uso \\
seguido de una línea en blanco y el uso \Large
como comando con argumentos. Los arreglé (pero quizás sean necesarios ajustes, dependiendo de su intención real).
Aquí hay una versión reducida del código.
\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}
La salida:
Aún recibirás dos advertencias de 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.
por lo que deberá verificar la configuración utilizada.
Actualizar
Comoegregavisos enhis comment
puede utilizar una prueba condicional para tener de forma segura \kern
en su definición:
\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
}