Estou tentando medir a altura de uma parte da minha página.
A página de título completa, junto com a parte da página que estou tentando medir, está destacada em vermelho, e o código para compilar a página é mostrado abaixo dela. Sim, tenho que medir tudo de uma vez.:-(
\documentclass[10pt]{extarticle}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage[a4paper,margin=.9in]{geometry}
\usepackage{xcolor}
\definecolor{palette2}{RGB}{235,249,249}
\usepackage[letterspace=400]{microtype}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{array}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\makeatletter
\fancypagestyle{plain}{
\fancyhf{}
\headrulecolor{lightgray}
\chead{\textit{Some science institution}}
\renewcommand{\headrulewidth}{.5pt}
}
\setlength\parindent\z@
\newcommand*\docparspacing{
\setlength\parindent{16pt}
\setlength\parskip{0pt}
}
\makeatother
\begin{document}
\thispagestyle{plain}
\raisebox{3.5ex}{\hbadness=9999
\colorbox{palette2}{\vrule width 0pt height 5.8ex \begin{tabular}{>{\RaggedRight\arraybackslash}p{\dimexpr.3\linewidth-\tabcolsep} >{\centering\arraybackslash}p{\dimexpr.35\linewidth-2\tabcolsep} >{\RaggedLeft\arraybackslash}p{\dimexpr.35\linewidth-4.4\tabcolsep}}
&
&
\end{tabular}}}
\vskip 2ex
\textcolor{lightgray}{\hrule height .5pt}
\vskip 6ex
\Huge{A title in fontsize Huge}
\vskip .4ex
\large{Doe, J. (John)}
\vskip 2ex
\normalsize
\vskip .5ex
\valign{%
\hsize=\dimexpr.5\linewidth-2\tabcolsep
\vskip 2ex
#\vfil\nointerlineskip
\vskip 1.5ex
\cr
\noindent\textls{\itshape\footnotesize KEYWORDS}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\itshape{obituary
linguist
typography}\cr
\noalign{\hfill}
\noindent\textls{\itshape\footnotesize ABSTRACT}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\small \lipsum[4] \cr
}\par
\vskip2ex
\hbox to\linewidth{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 3ex
\colorbox{palette2}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxsep}
\lipsum[1-2]
\end{minipage}%
}
\vskip 5ex
\docparspacing
\begin{multicols*}{3}
\section{Document structure}
\lipsum[1-3]
\end{multicols*}
\end{document}
Tentei medir isso criando minha própria caixa, que compila com oito erros e requer uso extensivo de \hbox
e \vbox
. Também exigiu que eu substituísse cada instância \hrule
por uma \leaders
variante, que requer cola (a ruína da minha existência). Suspeito fortemente que este seja o culpado da saída incorreta. No entanto, a minha principal questão é que a minha abordagem actual parece particularmente complicada, o que me leva a acreditar que a minha abordagem não é a correcta, ou seja, existe uma abordagem mais flexível (ou "fácil", se desejar). Como posso criar esta caixa para medição e utilização no documento, da forma mais acessível/flexível?
\documentclass[10pt]{extarticle}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage[a4paper,margin=.9in]{geometry}
\usepackage{xcolor}
\definecolor{palette2}{RGB}{235,249,249}
\usepackage[letterspace=400]{microtype}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{array}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\makeatletter
\fancypagestyle{plain}{
\fancyhf{}
\headrulecolor{lightgray}
\chead{\textit{Some science institution}}
\renewcommand{\headrulewidth}{.5pt}
}
\setlength\parindent\z@
\newcommand*\docparspacing{
\setlength\parindent{16pt}
\setlength\parskip{0pt}
}
\makeatother
\newsavebox\titlebox
\setbox\titlebox=\vbox{%
\hbox{\raisebox{3.5ex}{\hbadness=9999
\colorbox{palette2}{\vrule width 0pt height 5.8ex \begin{tabular}{>{\RaggedRight\arraybackslash}p{\dimexpr.3\linewidth-\tabcolsep} >{\centering\arraybackslash}p{\dimexpr.35\linewidth-2\tabcolsep} >{\RaggedLeft\arraybackslash}p{\dimexpr.35\linewidth-4.4\tabcolsep}}
&
&
\end{tabular}}}
}
\vskip 2ex
\hbox to \linewidth{\textcolor{lightgray}{\leaders\hrule height .5pt\hfil}}
\vskip 6ex
\hbox{\Huge{A title in fontsize Huge}}
\vskip .4ex
\hbox{\large{Doe, J. (John)}}
\vskip 2ex
\normalsize
\vskip .5ex
\valign{%
\hsize=\dimexpr.5\linewidth-2\tabcolsep
\vskip 2ex
#\vfil\nointerlineskip
\vskip 1.5ex
\cr
\noindent\textls{\itshape\footnotesize KEYWORDS}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfil}
\vskip 1.5ex
\itshape{obituary
linguist
typography}\cr
\noalign{\hfill}
\noindent\textls{\itshape\footnotesize ABSTRACT}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfil}
\vskip 1.5ex
\small \lipsum[4] \cr
}\par
\vskip2ex
\hbox to\linewidth{\color{lightgray}\leaders\hrule height .5pt\hfil}
\vskip 3ex
\colorbox{palette2}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxsep}
\lipsum[1-2]
\end{minipage}%
}
\vskip 5ex
}
\begin{document}
\thispagestyle{plain}
\usebox\titlebox
\docparspacing
\begin{multicols*}{3}
\section{Document structure}
\lipsum[1-3]
\end{multicols*}
\end{document}
Responder1
Você pode usar o tcolorbox
pacote (versão 3.12 (2014/07/29)
ou mais recente) para fazer a medição. Na minha solução, o kernel é um ambiente measurebox
construído pelo seguinte código:
\makeatletter
\newtcolorbox{measurebox}[1][]{blank,parbox=false,
show bounding box,
finish={\node[draw,fill=white,fill opacity=0.85,inner sep=5mm,
rounded corners,align=left,node font=\Large\bfseries]
at (frame.center) { width: \tcb@width,\\ height: \tcb@height};},
#1}
\makeatother
Qualquer parágrafo circundado por este ambiente tcolorbox
é medido e sua dimensão é escrita na tela ou no papel. O código completo é:
\documentclass[10pt]{extarticle}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage[a4paper,margin=.9in]{geometry}
\usepackage{xcolor}
\definecolor{palette2}{RGB}{235,249,249}
\usepackage[letterspace=400]{microtype}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{array}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage[many]{tcolorbox}% version `3.12 (2014/07/29)` or newer
\makeatletter% construct boxing environment
\newtcolorbox{measurebox}[1][]{blank,parbox=false,
show bounding box,
finish={\node[draw,fill=white,fill opacity=0.85,inner sep=5mm,
rounded corners,align=left,node font=\Large\bfseries]
at (frame.center) { width: \tcb@width,\\ height: \tcb@height};},
#1}
\makeatother% end construction
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\makeatletter
\fancypagestyle{plain}{
\fancyhf{}
\headrulecolor{lightgray}
\chead{\textit{Some science institution}}
\renewcommand{\headrulewidth}{.5pt}
}
\setlength\parindent\z@
\newcommand*\docparspacing{
\setlength\parindent{16pt}
\setlength\parskip{0pt}
}
\makeatother
\begin{document}
\thispagestyle{plain}
\begin{measurebox}%----- start measuring -----
\raisebox{3.5ex}{\hbadness=9999
\colorbox{palette2}{\vrule width 0pt height 5.8ex \begin{tabular}{>{\RaggedRight\arraybackslash}p{\dimexpr.3\linewidth-\tabcolsep} >{\centering\arraybackslash}p{\dimexpr.35\linewidth-2\tabcolsep} >{\RaggedLeft\arraybackslash}p{\dimexpr.35\linewidth-4.4\tabcolsep}}
&
&
\end{tabular}}}
\vskip 2ex
\textcolor{lightgray}{\hrule height .5pt}
\vskip 6ex
\Huge{A title in fontsize Huge}
\vskip .4ex
\large{Doe, J. (John)}
\vskip 2ex
\normalsize
\vskip .5ex
\valign{%
\hsize=\dimexpr.5\linewidth-2\tabcolsep
\vskip 2ex
#\vfil\nointerlineskip
\vskip 1.5ex
\cr
\noindent\textls{\itshape\footnotesize KEYWORDS}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\itshape{obituary
linguist
typography}\cr
\noalign{\hfill}
\noindent\textls{\itshape\footnotesize ABSTRACT}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\small \lipsum[4] \cr
}\par
\vskip2ex
\hbox to\linewidth{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 3ex
\colorbox{palette2}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxsep}
\lipsum[1-2]
\end{minipage}%
}
\vskip 5ex
\end{measurebox}%----- end measuring -----
\docparspacing
\begin{multicols*}{3}
\section{Document structure}
\lipsum[1-3]
\end{multicols*}
\end{document}
O ambiente measurebox
recebe um argumento opcional que pode ser usado para influenciar a caixa. Nesta aplicação, pode ser útil alterar o espaçamento antes ou depois da caixa, por exemplo,
\begin{measurebox}[before=\par\bigskip,
after=\par\vskip 10ex]
...
Segunda solução:
Esta é uma variante da primeira parte. Agora, a altura da caixa é salva em um parâmetro obrigatório measurebox
para uso posterior:
\makeatletter
\newtcolorbox{measurebox}[2][]{blank,parbox=false,
overlay={\xdef#2{\tcb@height}},
#1}
\makeatother
É usado da seguinte forma:
\begin{measurebox}{\myheight}
Todos juntos, isto é:
\documentclass[10pt]{extarticle}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage[a4paper,margin=.9in]{geometry}
\usepackage{xcolor}
\definecolor{palette2}{RGB}{235,249,249}
\usepackage[letterspace=400]{microtype}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{array}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage[many]{tcolorbox}
\makeatletter
\newtcolorbox{measurebox}[2][]{blank,parbox=false,
overlay={\xdef#2{\tcb@height}},
#1}
\makeatother
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\makeatletter
\fancypagestyle{plain}{
\fancyhf{}
\headrulecolor{lightgray}
\chead{\textit{Some science institution}}
\renewcommand{\headrulewidth}{.5pt}
}
\setlength\parindent\z@
\newcommand*\docparspacing{
\setlength\parindent{16pt}
\setlength\parskip{0pt}
}
\makeatother
\begin{document}
\thispagestyle{plain}
\begin{measurebox}{\myheight}
\raisebox{3.5ex}{\hbadness=9999
\colorbox{palette2}{\vrule width 0pt height 5.8ex \begin{tabular}{>{\RaggedRight\arraybackslash}p{\dimexpr.3\linewidth-\tabcolsep} >{\centering\arraybackslash}p{\dimexpr.35\linewidth-2\tabcolsep} >{\RaggedLeft\arraybackslash}p{\dimexpr.35\linewidth-4.4\tabcolsep}}
&
&
\end{tabular}}}
\vskip 2ex
\textcolor{lightgray}{\hrule height .5pt}
\vskip 6ex
\Huge{A title in fontsize Huge}
\vskip .4ex
\large{Doe, J. (John)}
\vskip 2ex
\normalsize
\vskip .5ex
\valign{%
\hsize=\dimexpr.5\linewidth-2\tabcolsep
\vskip 2ex
#\vfil\nointerlineskip
\vskip 1.5ex
\cr
\noindent\textls{\itshape\footnotesize KEYWORDS}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\itshape{obituary
linguist
typography}\cr
\noalign{\hfill}
\noindent\textls{\itshape\footnotesize ABSTRACT}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\small \lipsum[4] \cr
}\par
\vskip2ex
\hbox to\linewidth{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 3ex
\colorbox{palette2}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxsep}
\lipsum[1-2]
\end{minipage}%
}
\vskip 5ex
\end{measurebox}
\docparspacing
\begin{multicols*}{3}
\section{Document structure}
\textcolor{red}{The box above has a height of \myheight.}\par
\lipsum[1-3]
\end{multicols*}
\end{document}
Terceira solução:
A terceira solução omite tcolorbox
completamente. Uma macro \measurebox
é criada por
\newcommand{\measurebox}[4]{%
\sbox{#1}{\begin{minipage}{#2}#4%
\end{minipage}}%
\edef#3{\the\dimexpr\ht#1+\dp#1\relax}%
}
São necessários quatro parâmetros: #1
é um nome de caixa válido, #2
é uma largura, #3
é um nome de macro que obterá a altura total da caixa, #4
é o conteúdo da caixa. É usado da seguinte forma:
\newsavebox\titlebox
\measurebox{\titlebox}{\textwidth}{\myheight}{%----- start measuring
...
}%----- end measuring
%
\usebox\titlebox% somewhere
The box above has a height of \myheight.% somewhere
O código completo com a mesma saída acima é:
\documentclass[10pt]{extarticle}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage[a4paper,margin=.9in]{geometry}
\usepackage{xcolor}
\definecolor{palette2}{RGB}{235,249,249}
\usepackage[letterspace=400]{microtype}
\usepackage[english]{babel}
\usepackage{ragged2e}
\usepackage{array}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\makeatletter
\newcommand{\measurebox}[4]{%
\sbox{#1}{\begin{minipage}{#2}#4%
\end{minipage}}%
\edef#3{\the\dimexpr\ht#1+\dp#1\relax}%
}
\makeatother
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\makeatletter
\fancypagestyle{plain}{
\fancyhf{}
\headrulecolor{lightgray}
\chead{\textit{Some science institution}}
\renewcommand{\headrulewidth}{.5pt}
}
\setlength\parindent\z@
\newcommand*\docparspacing{
\setlength\parindent{16pt}
\setlength\parskip{0pt}
}
\makeatother
\begin{document}
\thispagestyle{plain}
\newsavebox\titlebox
\measurebox{\titlebox}{\textwidth}{\myheight}{%----- start measuring
\raisebox{3.5ex}{\hbadness=9999
\colorbox{palette2}{\vrule width 0pt height 5.8ex \begin{tabular}{>{\RaggedRight\arraybackslash}p{\dimexpr.3\linewidth-\tabcolsep} >{\centering\arraybackslash}p{\dimexpr.35\linewidth-2\tabcolsep} >{\RaggedLeft\arraybackslash}p{\dimexpr.35\linewidth-4.4\tabcolsep}}
&
&
\end{tabular}}}
\vskip 2ex
\textcolor{lightgray}{\hrule height .5pt}
\vskip 6ex
\Huge{A title in fontsize Huge}
\vskip .4ex
\large{Doe, J. (John)}
\vskip 2ex
\normalsize
\vskip .5ex
\valign{%
\hsize=\dimexpr.5\linewidth-2\tabcolsep
\vskip 2ex
#\vfil\nointerlineskip
\vskip 1.5ex
\cr
\noindent\textls{\itshape\footnotesize KEYWORDS}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\itshape{obituary
linguist
typography}\cr
\noalign{\hfill}
\noindent\textls{\itshape\footnotesize ABSTRACT}
\vskip -1.5ex
\hbox to\hsize{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 1.5ex
\small \lipsum[4] \cr
}\par
\vskip2ex
\hbox to\linewidth{\color{lightgray}\leaders\hrule height .5pt\hfill}
\vskip 3ex
\colorbox{palette2}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxsep}
\lipsum[1-2]
\end{minipage}%
}
\vskip 5ex
}%----- end measuring
%
\usebox\titlebox
\docparspacing
\begin{multicols*}{3}
\section{Document structure}
\textcolor{red}{The box above has a height of \myheight.}\par
\lipsum[1-3]
\end{multicols*}
\end{document}
Observe que você deve usar a medição depois \begin{document}
, mas você pode medir quantas caixas quiser antes de usar qualquer uma delas.