macro (newcommand) Por que algum texto não está chegando na saída?

macro (newcommand) Por que algum texto não está chegando na saída?

Quero repetir alguns textos e tabelas na mesma página. Estou tentando o código abaixo, mas ele imprime apenas uma vez e novamente não imprime a régua no final. O código completo é fornecido abaixo.

\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}

Responder1

O principal problema aqui é com a linha

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

na definição de \myrule. Para entender o problema, veja o queO TeXbook(curva dupla perigosa no final da página 79) diz sobre \prevdepth:

No entanto, \prevdepthé definido como valor sentinela −1000pt no início de uma lista vertical ou logo após uma caixa de regras; isso serve para suprimir a próxima cola entrelinhas.

Então, a segunda vez que você usa seu comando, \prevdepthé -1000pte você faz um salto vertical de -1000pt(aproximadamente -14in!) antes de compor o material; o material, obviamente, é empurrado para cima, para fora da página.

Além disso, existem outros problemas com o código, como usar \\seguido de linha em branco e usar \Largecomo comando com argumentos. Eu os consertei (mas talvez sejam necessários ajustes, dependendo da sua intenção real).

Aqui está uma versão reduzida do 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}

A saída:

insira a descrição da imagem aqui

Você ainda receberá dois avisos 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.

então você precisará verificar as configurações usadas.

Atualizar

Comoegrégiaavisos emhis commentvocê pode usar um teste condicional para ter segurança \kernem sua definição:

\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
}

informação relacionada