\hrule después de descendientes

\hrule después de descendientes

Estoy intentando rehacer mi CV en látex y tengo un problema menor con la ubicación de \hrule. Defino un entorno de categoría para cada sección a través de

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

Cuando tengo una \begin{categoría}{XXX}, el espacio entre la línea inferior del texto y la regla hrule se hace más grande si XXX tiene descendentes. Preferiría que se mantuviera constante y que los descendentes estuvieran más cerca de la línea. ¿Hay alguna manera de hacer esto?

Respuesta1

El \hrulematerial vertical rompe la línea de base de salto de cuadrícula porque restablece el \prevdepthregistro interno. Pero puede guardar el valor del registro en una variable, imprimir \hruley restaurar este registro. Entonces se puede mantener la cuadrícula de salto de línea base.

Comportamiento 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.

Manteniendo \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)

Cambiando \hrulea la cuadrícula:

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.

Entonces, puedes definir \myhruley hacer esto:

\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

Respuesta2

TeX no inserta pegamento entre líneas antes y después \hrule, por lo que debes enseñarle que quieres respetar las distancias independientemente de los ascendentes y descendentes. La forma más sencilla es utilizar puntales:

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

La “categoría” está rodeada de puntales y, justo antes de imprimir el primer elemento, pretendemos que la línea anterior tenga una profundidad igual a la de un puntal ( \prevdepth=\dp\strutbox).

Compuse los dos ejemplos en minipáginas para ver mejor que la alineación vertical es la deseada. Las dos pesadas reglas sólo marcan los límites. Al \vspace{0pt}comienzo de las minipáginas es nuevamente solo para el ejemplo, establecerá el punto de alineación de los dos cuadros.

ingrese la descripción de la imagen aquí

Respuesta3

Puede eliminar la profundidad del descensor usando \raisebox. La siguiente definición de \raiseboxestá contenida ensource2e.pdf:

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

Se eleva ⟨box⟩en ⟨distance⟩longitud (hacia abajo si es ⟨distance⟩negativo). Hace que TeX piense que el nuevo cuadro se extiende ⟨height⟩por encima de la línea y ⟨depth⟩por debajo, para una longitud vertical total de ⟨height⟩+ ⟨depth⟩. Valores predeterminados de ⟨height⟩& ⟨depth⟩= altura y profundidad reales del cuadro en la nueva posición.

Entonces, considere usar \raisebox{0pt}[\height][0pt]{<stuff>}( \heightes la altura natural de <stuff>):

ingrese la descripción de la imagen aquí

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

Tenga en cuenta el uso de \parpara ingresar al modo vertical. De lo contrario, el (primer) uso de \medskipes superfluo y solo se emite más tarde (una vez en modo vertical a través de algún otro medio).

Más extremo podría ser \smashel contenido, por lo que no ocupa ninguna altura/profundidad vertical (similar a \raisebox{0pt}[0pt][0pt]{<stuff>}).

información relacionada