미니페이지에서 정렬된 타자기 텍스트의 모양을 개선하는 방법

미니페이지에서 정렬된 타자기 텍스트의 모양을 개선하는 방법

코드를 고려해보세요:

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

생산하는

여기에 이미지 설명을 입력하세요

두 번째 미니페이지는 내가 찾고 있는 결과를 생성하지만(출력의 마지막 줄을 중앙에 두고 왼쪽과 오른쪽으로 정렬된 tttext) 첫 번째 미니페이지의 정렬된 출력에 비해 모양이 희미해 보입니다.

나는 패키지를 호출하여 생각했습니다 ragged2e. 그러나 그렇게 하면 texttt텍스트의 마지막 줄을 중앙에 맞추는 것 외에 상황이 훨씬 더 악화되었습니다.

질문: (가능하다면 간단하게) 텍스트 정렬 출력의 모양을 개선할 수 있는 방법은 무엇입니까 texttt(예: 줄 사이의 간격 줄이기, 단어 사이의 간격 줄이기—출력 줄 수 줄이기)?

나는 다음과 같이 코드를 컴파일한다.lualatex

감사합니다.

답변1

단어 간 간격이 늘어나서 고정 폭 문자 정렬이 없으므로 가변 폭 타자기 글꼴을 사용하는 것이 더 좋습니다. 고정 폭을 정당화하는 것은 항상 끔찍해 보이기 때문입니다.

lvmtt는 기본적으로 하이픈 넣기와 가변 단어 간 공백을 허용하므로 더 적은 수의 설정이 필요합니다.

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

오늘은 이미지가 없지만여기에서 출력을 참조하세요

답변2

위의 의견에 따라 이것은 유사하지만 다른 접근 방식입니다.

\DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font=1}서문에 사용하세요 . (font=1을 사용하면 하이픈을 넣을 때 대시를 사용할 수 있습니다. 글꼴=-1을 사용하면 하이픈을 사용할 수 있지만 대시는 사용할 수 없습니다.)

또한 글꼴 크기를 줄이면 미적 측면도 향상됩니다.

이제 코드는

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

출력을 생성합니다.

여기에 이미지 설명을 입력하세요

두 번째 문단에는 하이픈을 넣을 내용이 없었기 때문에 세 번째 문단에 하이픈을 추가하여 코드가하다하이픈을 생성합니다.

답변3

그런 것을 개선하는 것은 어렵습니다. 고정 폭 글꼴에는 일반적으로 단어 간 확장성 및 축소성이 없습니다. 왜냐하면 행 간 문자 정렬이 필요한 텍스트를 재현하는 데 주로 사용되며 이를 달성하기 위해 단어 간 공간이 문자만큼 넓은 길이로 고정되어 있기 때문입니다.

이러한 글꼴은 일반적으로 해당 글꼴을 비활성화하여 하이픈 넣기를 허용하지 않습니다 \hyphenchar. pdflatexOT1 인코딩의 기본 글꼴을 사용하면 읽을 수 있습니다 ot1cmtt.fd.

\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%
      }{}
[...]

그리고 \m@ne를 의미합니다 -1. 대부분의 글꼴에는 선언이 없습니다. \hyphenchar이 경우 TeX는 \defaulthyphenchar값 45(하이픈의 글꼴 슬롯)를 보유하는 를 사용하기 때문입니다. 단어 사이의 공백 값은 대신 파일에 저장되며 .tfm적절한 매개변수에 따라 값을 변경할 수 있습니다 \fontdimen.

대신 lualatex다음과 같이 tulmtt.fd사용됩니다.

\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@
}
[...]

따라서 단어간 공간의 신축성과 수축성이 강제로 제거됩니다.

그러나 글꼴 매개변수에 대한 할당은 본질적으로 전역적이라는 점을 기억해야 합니다. 축어적인 자료나 목록에도 고정폭 글꼴을 사용하려는 경우 minipage.

나는 이것이 사실이 아니라고 가정합니다.

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

여기에 이미지 설명을 입력하세요

답변4

문제는 을 설정하여 단어 사이에 큰 공백을 설정했다는 것입니다 \spaceskip. 귀하의 질문을 바꿔서 설명하겠습니다. "TeX 프리미티브를 사용하여 큰 공간을 설정했는데 \spaceskip왜 큰 공간이 있습니까?"

공백을 적게 설정하면 \spaceskip원하는 결과를 얻을 수 있습니다. 또한 글꼴에 하이픈 문자를 설정했는데 \tt이는 다른 답변에서도 여기에 언급되어 있습니다.

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

관련 정보