\hrule depois dos descendentes

\hrule depois dos descendentes

Estou tentando refazer meu currículo em látex e estou tendo um pequeno problema com a colocação de \hrule. Eu defino um ambiente de categoria para cada seção via

\newenvironment{category}[1]
{%                                                                                                                            
{\bf{#1}}                                                                                                                     
  \medskip                                                                                                            
  \hrule % Horizontal line                                                                                                    
  \medskip                                                                                                            
\begin{itemize}[label={$-$},itemsep=0.15cm]                                                                                   
}
{%                                                                                                                            
\end{itemize}                                                                                                                 
\bigskip                                                                                                                      
}

Quando tenho uma \begin{category}{XXX}, o espaço entre a linha inferior do texto e a hrule fica maior se XXX tiver descendentes. Prefiro que permaneça constante e que os descendentes estejam mais próximos da linha. Há alguma maneira de fazer isso?

Responder1

O \hrulematerial vertical quebra a grade de base porque redefine o \prevdepthregistro interno. Mas você pode salvar o valor do registro em uma variável, imprimir \hrulee restaurar esse registro. Então a grade baseskip pode ser mantida.

Comportamento normal:

Previous line
\hrule     % this rule is printed immediately below the line without space.
Next line  % this line is printed without space because \prevdepth is reset.

Guardando \prevdepth:

Previous line
\par \dimen0=\prevdepth  % the \prevdepth value is saved
\hrule     % this rule is printed immediately below the line without space.
\prevdepth=\dimen0   % restoring \prevdepth
Next line  % this line keeps the baselineskip-grid
           % but .4pt is added (the rule thickness)

Mudando \hrulepara a grade:

Previous line
\par \dimen0=\prevdepth  % the \prevdepth value is saved
\kern \dimexpr 3pt-\prevdepth  % the space 3pt from baseline
\hrule     % hrule 3pt from previous baseline
\prevdepth=\dimen0   % restoring \prevdepth
\kern \dimexpr \prevdepth-3pt-.4pt \relax % space correction
Next line % Next line fits to baselineskip-grid.

Então, você pode definir \myhrulee fazer isso:

\newdimen\tmpdim
\def\myhrule{\par
   \tmpdim=\prevdepth
   \kern\dimexpr 3pt-\prevdepth
   \hrule
   \prevdepth=\tmpdim
   \kern\dimexpr \prevdepth-3pt-.4pt \relax
}

Previous line.
\myhrule
Next line.

\bye

Responder2

O TeX não insere cola entre linhas antes e depois \hrule, então você tem que ensiná-lo que deseja respeitar as distâncias independentemente dos ascendentes e descendentes. A maneira mais simples é usar struts:

\documentclass{article}
\usepackage{enumitem}

\newenvironment{category}[1]
 {\par\noindent\textbf{\strut#1\strut}
  \medskip % <-------- adjust here
  \hrule % Horizontal line
  \medskip
  \begin{itemize}[label={--},itemsep=0.15cm]
  \prevdepth=\dp\strutbox
 }
 {\end{itemize}
  \bigskip
 }

\begin{document}

\hrule height 4pt % just to see the two boxes
\noindent
\begin{minipage}[t]{0.45\textwidth}
\vspace{0pt}% to set the alignment point
Some text before
\begin{category}{abcd}
\item acer
\end{category}
Some text after
\end{minipage}
\begin{minipage}[t]{0.45\textwidth}
\vspace{0pt}% to set the alignment point
Some text before
\begin{category}{ghij}
\item dgf
\end{category}
Some text after
\end{minipage}

\hrule height 4pt % just to see that the two boxes 
\end{document}

A “categoria” é cercada por escoras e, pouco antes de o primeiro item ser impresso, fingimos que a linha anterior tinha profundidade igual à de uma escora ( \prevdepth=\dp\strutbox).

Digitei os dois exemplos em minipáginas para ver melhor se o alinhamento vertical está conforme desejado. As duas regras pesadas apenas marcam os limites. O \vspace{0pt}início das minipáginas é novamente apenas para exemplo, irá definir o ponto de alinhamento das duas caixas.

insira a descrição da imagem aqui

Responder3

Você pode remover a profundidade do descendente usando \raisebox. A seguinte definição de \raiseboxestá contida emsource2e.pdf:

\raisebox{⟨distance⟩}[⟨height⟩][⟨depth⟩]{⟨box⟩}

Aumenta ⟨box⟩em ⟨distance⟩comprimento (para baixo se for ⟨distance⟩negativo). Faz o TeX pensar que a nova caixa se estende ⟨height⟩acima e abaixo da linha ⟨depth⟩, por um comprimento vertical total de ⟨height⟩+ ⟨depth⟩. Valores padrão de ⟨height⟩& ⟨depth⟩= altura e profundidade reais da caixa na nova posição.

Então, considere usar \raisebox{0pt}[\height][0pt]{<stuff>}( \heighté a altura natural de <stuff>):

insira a descrição da imagem aqui

\documentclass{article}

\usepackage{enumitem}

\newenvironment{category}[1]{%
    \par\noindent% No paragraph indent
    \raisebox{0pt}[\height][0pt]{\textbf{#1}}\par
    \medskip
    \hrule% Horizontal rule
    \medskip
    \begin{itemize}[label={--},itemsep=.5em]
  }{%
    \end{itemize}
    \bigskip
  }

\begin{document}

Here is some content
\begin{category}{abcdef}
  \item something
  \item something else
\end{category}

Some more content
\begin{category}{ghijkl}
  \item something
  \item something else
\end{category}

\end{document}

Observe o uso de \parpara entrar no modo vertical. Caso contrário, o (primeiro) uso de \medskipé supérfluo e só será emitido posteriormente (uma vez no modo vertical por algum outro meio).

Mais extremo pode ser \smasho conteúdo, de modo que não ocupe nenhuma altura/profundidade vertical (semelhante a \raisebox{0pt}[0pt][0pt]{<stuff>}).

informação relacionada