
다음과 유사하지만 같지는 않은 새로운 환경을 정의했습니다 listings
.
\documentclass{ltxdoc}
\usepackage{lipsum}
\newenvironment{lines}
{\par\begingroup\nobreak
\vspace{3pt}\parindent0pt\hrule\kern5pt
\nobreak\obeylines\everypar{\strut}\endgroup}
{\par\begingroup\nobreak
\vspace{3pt}\parindent0pt\hrule\kern5pt
\nobreak\obeylines\everypar{\strut}\endgroup%
\noindent%
}
\begin{document}
\lipsum[1]
\begin{lines}
Some nifty code and stuffz
\end{lines}
\lipsum[2]
\end{document}
왜 \noindent
텍스트 앞에 작은 공백을 두나요? 내가 뭐 놓친 거 없니?
답변1
사용하면 \noindent
거의 항상 이런 동작이 발생합니다. 공백은 환경 뒤에 줄 끝에서 조판되는 단어 간 공백입니다.
\ignorespacesafterend
균열을 종이로 덮는 것을 사용하면 문제를 피할 수 있습니다 . \noindent
가로 모드를 조기에 시작한 오류는 줄 끝이 공백으로 조판되는 이유입니다. LaTeX 환경에서는 절대 이런 일이 발생하지 않습니다. 을 사용하여 환경을 정의해야 합니다. trivlist
그러면 환경은 수직 모드로 종료되지만 뒤에 빈 줄이 없으면 들여쓰기가 억제됩니다(실제로는 를 사용하여 \lastbox
추가되지 않고 을 사용하여 제거됩니다 \noindent
.)
이런 식으로 길이를 적절하게 조정하십시오.
\documentclass{ltxdoc}
\usepackage{lipsum}
\newenvironment{linez}
{\trivlist\nopagebreak
\parindent0pt
\vspace{3pt}%
\hrule
\vspace{-3pt}%
\item\relax\obeylines}
{\par
\nopagebreak
\vspace{3pt}%
\hrule
\vspace{3pt}%
\endtrivlist}
\begin{document}
\lipsum[1]
\begin{linez}
Some nifty code and stuffz
Some nifty code and stuffz
Some nifty code and stuffz
Some nifty code and stuffz
\end{linez}
\lipsum[2]
\end{document}
답변2
누락되었지만 \ignorespacesafterend
정의가 수행되지 않습니다 \obeylines
. 그룹에 포함하고 그 효과가 다음에서 사라지기 때문입니다 \endgroup
.
\documentclass{ltxdoc}
\usepackage{lipsum}
\newenvironment{linez}
{\par\nopagebreak
\vspace{3pt}
\parindent0pt
\hrule\kern5pt
\obeylines}
{\par
\nopagebreak
\vspace{3pt}
\hrule\kern5pt
\noindent\ignorespacesafterend}
\begin{document}
\lipsum[1]
\begin{linez}
Some nifty code and stuffz
Some nifty code and stuffz
Some nifty code and stuffz
Some nifty code and stuffz
\end{linez}
\lipsum[2]
\end{document}