지금 문서를 입력 warning
중이고 amsthm
. 내 흥미를 끄는 것은 Knuth의 것입니다.TeXbook환경으로 보이는 것 앞에 "위험한 굴곡" 기호를 배치하는 데 성공했습니다 exercise
. 기호는 정확히 두 줄에 걸쳐 있으며 굵은 글씨 EXERCISE
와 다음 텍스트가 해당 기호를 둘러싸므로 세 번째 줄이 시작되고 다시 왼쪽 여백이 표시됩니다.
내 질문은 바람직하게는 (수정된) 환경에서 이것을 재현할 수 있는지 여부입니다 amsthm
. trivlist
환경 구현 시 문제가 발생한다는 amsthm
것을 알고 있지만 trivlist
. 머리글 이전에도 위험한 굴곡이 나타납니다(예: 5페이지).TeXbook).
답변1
귀하의 답변에는 꽤 좋은 코드가 있지만 개선될 수 있습니다. 특히 저는 대신을 사용하므로 다음 \clubpenalties
과 같이 \clubpenalty
할 수 있습니다.
- 두 번째 줄 이후에 페이지 나누기를 방지합니다.
- clobbering에 대해 걱정하지 마십시오
\clubpenalty
; \clubpenalties
후크로 다시 설정하세요 .
헤더도 조판했어요~ 후에\label
단락이 시작되므로 공백을 걱정하지 않고 사용할 수 있습니다 .
한 줄 경고의 경우 첫 번째 문단의 끝을 검사하여 \prevgraf
1이면 페이지 나누기가 불가능한 빈 줄이 생성됩니다.
\documentclass{article}
\usepackage{manfnt} % for \dbend
\usepackage{lipsum} % for testing
\counterwithin{equation}{section}
\newlength{\dangerwidth} % width of \dbend
\settowidth{\dangerwidth}{\dbend}
\addtolength{\dangerwidth}{1em} % add any extra space between \dbend and text
\NewDocumentEnvironment{warning}{o}{%
% I mostly use equation counter, feel free to use any other one
% default \topsep before theorem environment
\par\addvspace{\topsep}
% no line break after first line and discourage after second line
\clubpenalties=3 10000 5000 0
% after first paragraph, reset \clubpenalties
\AddToHookNext{para/end}{\clubpenalties=0 }%
% after first paragraph, count the number of lines, if one add an empty line and no page break
\AddToHookNext{para/after}{\ifnum\prevgraf=1 \nopagebreak\hbox{}\fi}%
% specifying indentation of first two lines
\hangindent=\dangerwidth \hangafter=-2
% step the associated counter
\refstepcounter{equation}%
% store the start so to allow for \label
\everypar\expandafter{%
% remove the indentation box
{\setbox0=\lastbox}% <---- !!!!!!!
% zero width \dbend, shifted to left border
\makebox[0pt]{\hspace*{-\hangindent}\dbend\hfill}%
% theorem name and number
\textbf{Warning \theequation}%
% the attribution, if given
\IfValueT{#1}{ (#1)}%
% punctuation and space after
\textbf{.}\hspace*{5pt plus 1pt minus 1pt}%
% reset \everypar
\everypar{}%
}%
% ignore spaces at the beginning
\ignorespaces
}{
% end the paragraph
\par
% default space after the environment
\addvspace{\topsep}%
}
\begin{document}
\lipsum[66]
\begin{warning}[a note]\label{xyz}
\lipsum[66]
\lipsum[66]
\end{warning}
\begin{warning}
\lipsum[66]
\end{warning}
\lipsum[66]
\begin{warning}
One single line looks weird.
\end{warning}
Let's see the reference \ref{xyz}
\lipsum[66]
\end{document}
답변2
많은 고민 끝에 만족스러운 결과를 얻었다고 생각합니다. 나는 환경에서 기본 매개변수를 가져왔고 amsthm
Knuth의 것에서 영감을 얻었습니다.TeXbook암호.
\documentclass{article}
\usepackage{manfnt} % for \dbend
\usepackage{lipsum} % for testing
\newlength{\dangerwidth} % width of \dbend
\settowidth{\dangerwidth}{\dbend}
\addtolength{\dangerwidth}{1em} % add any extra space between \dbend and text
\newenvironment{warning}[1][]{
\begingroup % local definition
\stepcounter{equation} % I mostly use equation counter, feel free to use any other one
\par\addvspace{\topsep} % default \topsep before theorem environment
\clubpenalty=10000 % no line break after first line
\hangindent=\dangerwidth \hangafter=-2 % specifying indentation of first two lines
\noindent\makebox[0pt]{\hspace*{-\hangindent}\dbend\hfill}% % zero width \dbend, shifted to left boarder
\textbf{Warning \thesection.\theequation}% % theorem name and number
\if\relax\detokenize{#1}\relax\else % optional argument, check if empty
\space(#1)% % if so, type optional argument in parenthesis
\fi
\textbf{.}\hspace*{5pt plus 1pt minus 1pt}\ignorespaces % add default rubber after theorem header
}{
\par\addvspace{\topsep}\endgroup % default \topsep after environment
}
\begin{document}
\lipsum[66]
\begin{warning}[a note]
\lipsum[66]
\lipsum[66]
\end{warning}
\begin{warning}
\lipsum[66]
\end{warning}
\lipsum[66]
\begin{warning}
One single line looks weird.
\end{warning}
\end{document}
두 가지 질문이 있습니다.
- 현재로서는
\clubpenalty=10000
전체 환경에 적용됩니다. 어떻게든 이 환경 내의 첫 번째 문단에만 적용할 수 있나요? ~ 안에TeXbook, Knuth는 각 "위험한" 단락에 위험한 굽힘 기호를 포함해야 했기 때문에 이 문제를 해결하지 못했습니다. - 에서 볼 수 있듯이경고 0.3, 한 줄은 그다지 좋아 보이지 않습니다. 이 문제를 해결하는 방법이 있나요? 내부에 선이 하나만 있으면 발의 중심이 기준선에 있지 않고 누구의 발 대신
warning
사용할 수 있는지 제안합니다. 이것을 어떻게 감지합니까?\textdbend
\dbend
amsthm
원래 환경에서 누락된 부분이나 위 코드의 개선 사항 에 대해 자유롭게 의견을 보내주세요 .