
Considere el código:
\documentclass[12pt]{book}
\usepackage{microtype}
%\usepackage{ragged2e}
\begin{document}
\thispagestyle{empty}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\textbf{This is a minipage. The above line of commands justifies the text and centers the last line. Notice how "nice" it appears.}
\end{minipage}
\end{LARGE}
\end{center}
\vspace*{25pt}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\spaceskip1em plus 1em \xspaceskip 1em plus 2em\relax
\texttt{I have, with the two above lines of commands, been able to justify the tttext in this minipage, as well as center the last line of output. This is what I want; however, the appearance does not seem as "nice" as the content of the above minipage.}
\end{minipage}
\end{LARGE}
\end{center}
\end{document}
que produce
Aunque la segunda minipágina produce lo que estoy buscando (texto justificado a izquierda y derecha con la última línea de salida centrada), la apariencia parece palidecer en comparación con la salida justificada de la primera minipágina.
Pensé invocando el ragged2e
paquete; pero al hacerlo, además de centrar la última línea de texttt
texto, empeoró mucho las cosas.
PREGUNTA: ¿Cómo puedo (simplemente, si es posible) mejorar la apariencia del texttt
texto justificado (por ejemplo, reducir el espacio entre líneas, reducir el espacio entre palabras, para reducir el número de líneas de resultado)?
Compilo el código conlualatex
Gracias.
Respuesta1
Como tiene espacios entre palabras elásticos, no hay alineación de caracteres monoespaciados, sería mejor usar una fuente de máquina de escribir de ancho variable, ya que justificar el monoespacio siempre se verá horrible.
lvmtt permite la separación de palabras y el espacio variable entre palabras de forma predeterminada, por lo que se requieren menos configuraciones.
\documentclass[12pt]{book}
\usepackage{microtype}
%\usepackage{ragged2e}
\begin{document}
\thispagestyle{empty}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\textbf{This is a minipage. The above line of commands justifies the
text and centers the last line. Notice how "nice" it appears.}
\end{minipage}
\end{LARGE}
\end{center}
\vspace*{25pt}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\fontfamily{lmvtt}\selectfont
I
have, with the two above lines of commands, been able to justify
the tttext in this minipage, as well as center the last line of
output. This is what I want; however, the appearance does not seem
as "nice" as the content of the above minipage.
\end{minipage}
\end{LARGE}
\end{center}
\end{document}
No hay imagen hoy perover salida aquí
Respuesta2
En la línea de los comentarios anteriores, este es un enfoque similar, pero diferente:
Uso \DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font=1}
en el preámbulo. (La fuente = 1 permite el uso de un guión al dividir con guiones; la fuente = -1 permite la división de palabras pero sin guión).
Además, disminuir el tamaño de la fuente también debería mejorar la estética.
Ahora, el código
\documentclass[12pt]{book}
\usepackage{microtype}
\DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font=1}
\begin{document}
\thispagestyle{empty}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\textbf{This is a minipage. The above line of commands justifies the text and centers the last line. Notice how "nice" it appears.}
\end{minipage}
\end{LARGE}
\end{center}
\vspace*{25pt}
\begin{center}
\begin{large}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\spaceskip1em plus 1em \xspaceskip 1em plus 2em\relax
\texttt{This is a minipage. The above line of commands justifies the text and centers the last line. Notice how "nice" it appears.}
\end{minipage}
\end{large}
\end{center}
\vspace*{25pt}
\begin{center}
\begin{large}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\spaceskip1em plus 1em \xspaceskip 1em plus 2em\relax
\texttt{This is a minipage. Supercalifragilisticexpialidocious Supercalifragilisticexpialidocious Supercalifragilisticexpialidocious Supercalifragilisticexpialidocious Supercalifragilisticexpialidocious}
\end{minipage}
\end{large}
\end{center}
\end{document}
produce la salida:
Como no había nada que dividir con guiones en el segundo párrafo, puse un tercero para ilustrar que el códigohaceproducir separación de palabras.
Respuesta3
Es difícil mejorar algo así. Las fuentes monoespaciadas generalmente no tienen capacidad de extensión ni contracción entre palabras, ya que se usan principalmente para reproducir texto donde se desea la alineación de caracteres entre filas y, para lograr esto, el espacio entre palabras se establece en una longitud rígida tan ancha como los caracteres.
Por lo general, estas fuentes no permiten la separación de palabras, deshabilitándolas \hyphenchar
. Con pdflatex
y las fuentes predeterminadas en codificación OT1 podemos leer ot1cmtt.fd
para ver
\ProvidesFile{ot1cmtt.fd}
[2019/12/16 v2.5j Standard LaTeX font definitions]
\DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font\m@ne}
\DeclareFontShape{OT1}{cmtt}{m}{n}
{%
<5><6><7><8>cmtt8<9>cmtt9%
<10><10.95>cmtt10%
<12><14.4><17.28><20.74><24.88>cmtt12%
}{}
[...]
y \m@ne
significa -1
. La mayoría de las fuentes no tendrán \hyphenchar
declaración porque en ese caso TeX usará \defaulthyphenchar
, que contiene el valor 45 (la ranura de fuente para el guión). En cambio, los valores de los espacios entre palabras se almacenan en el .tfm
archivo y puede cambiarlos actuando sobre los \fontdimen
parámetros apropiados.
Con lualatex
en su lugar tulmtt.fd
se utilizaría:
\ProvidesFile{tulmtt.fd}
[2021/07/23 v1.8a Standard LaTeX font definitions for Latin Modern]
\DeclareFontFamily{TU}{lmtt}{%
\hyphenchar \font\m@ne
\fontdimen3\font\z@
\fontdimen4\font\z@
}
[...]
por lo que la capacidad de extensión y contracción de los espacios entre palabras se eliminan por la fuerza.
Sin embargo, debe recordar que las asignaciones a los parámetros de fuente son inherentemente globales: si planea usar la fuente monoespaciada también para material textual o listados, deberá revertir esas asignaciones al final de su archivo minipage
.
Supongo que este no es el caso.
\documentclass[12pt]{book}
\usepackage{microtype}
\newenvironment{monospacedquote}{%
\begin{center}
\begin{minipage}{5.75in}
\LARGE
\ttfamily
\ifnum\hyphenchar\font=-1
\hyphenchar\font=`-
\fontdimen3\font=0.5\fontdimen2\font
\fontdimen4\font=0.3\fontdimen2\font
\fontdimen7\font=0.2\fontdimen2\font
\fi
\selectfont
\leftskip=\fill
\rightskip=-\leftskip
\parfillskip=\stretch{2}%
}{\end{minipage}\end{center}}
\begin{document}
\begin{monospacedquote}
This is a minipage. The above line of commands justifies the text
and centers the last line. Notice how awful it appears.
\end{monospacedquote}
\end{document}
Respuesta4
Tu problema es que has establecido grandes espacios entre palabras al configurar \spaceskip
. Intento parafrasear tu pregunta: "He establecido espacios grandes usando TeX primitivo \spaceskip
, ¿por qué tengo espacios grandes?"
Si establece una menor cantidad de espacios, \spaceskip
obtendrá el resultado deseado. Además, configuré guión para \tt
la fuente, esto también se menciona aquí en otras respuestas.
\documentclass[12pt]{book}
\usepackage{microtype}
\begin{document}
\thispagestyle{empty}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\textbf{This is a minipage. The above line of commands justifies the text and centers the last line. Notice how "nice" it appears.}
\end{minipage}
\end{LARGE}
\end{center}
\vspace*{25pt}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
%\spaceskip1em plus 1em \xspaceskip 1em plus 2em\relax %% ??? why this?
\spaceskip.3em plus .2em minus .1em \xspaceskip=\spaceskip {\tt\hyphenchar\font=`-}%
\texttt{I have, with the two above lines of commands, been able to justify the tttext in this minipage, as well as center the last line of output. This is what I want; however, the appearance does not seem as "nice" as the content of the above minipage.}
\end{minipage}
\end{LARGE}
\end{center}
\end{document}