![라텍스에서 장의 마지막 줄이 새 페이지로 늘어나는 것을 방지하는 방법](https://rvso.com/image/405353/%EB%9D%BC%ED%85%8D%EC%8A%A4%EC%97%90%EC%84%9C%20%EC%9E%A5%EC%9D%98%20%EB%A7%88%EC%A7%80%EB%A7%89%20%EC%A4%84%EC%9D%B4%20%EC%83%88%20%ED%8E%98%EC%9D%B4%EC%A7%80%EB%A1%9C%20%EB%8A%98%EC%96%B4%EB%82%98%EB%8A%94%20%EA%B2%83%EC%9D%84%20%EB%B0%A9%EC%A7%80%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
를 사용하여 tex 문서를 작성하고 있습니다 \documentclass{book}
. 여러 챕터로 구성되어 있으며 아래 코드를 사용하여 새 장이 같은 페이지에서 시작되도록 합니다.
\makeatletter
\patchcmd\chapter
{\if@openright\cleardoublepage\else\clearpage\fi}
{\par}% Inserting a \par here!
{}{}
\makeatother
이제 다른 문제에 직면하게 되었습니다(아래 첨부된 스크린샷 참조). 보시다시피, 사용 가능한 공간이 충분하더라도 장의 마지막 줄(2페이지)이 새 페이지로 확장됩니다. 이것을 피할 수 있는 방법이 있습니까? "경건"(마지막 단어)이라는 단어가 있는 1장이 같은 페이지에서 끝나도록 할 수 있습니까?
답변1
\penalty
교체품 뒤에 작은 것을 추가하면 \par
원하는 것을 얻을 수 있습니다.
\documentclass[12pt]{book}
\usepackage{titlesec}
\usepackage{etoolbox}
\makeatletter
\patchcmd\chapter
{\if@openright\cleardoublepage\else\clearpage\fi}
{\par\penalty100}% Inserting a \par here and allowing page breaks!
{}{}
\makeatother
\usepackage{duckuments} % only needed for the dummy text of `\blindduck`
\begin{document}
\chapter{Some Chapter}
\blindduck[1-3]
\chapter{Some Chapter}
\blindduck
\end{document}
페널티가 없는 페이지 2:
페널티가 있는 페이지 2:
답변2
다음은 패키지에 대한 코드 데모입니다 nowidow
.
\documentclass[12pt, openany]{report}%openany makes chap start on each new page
\usepackage{graphicx}
% \usepackage[contents={}]{background} %{} removes draft from all pages
\usepackage{fancyhdr}
\usepackage{fontspec}
\usepackage{titlesec} %to use titleformat for editing chapter title
\titleformat{\chapter}[block]{\filcenter\LARGE\bfseries}{\MakeUppercase{\chaptername}\,\Roman{chapter}}{0.5em}{}
\setmainfont{EB Garamond}%Constantia
\usepackage{etoolbox} %to start a new chapter on the same page
\makeatletter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother
\usepackage[defaultlines=2]{nowidow}
\begin{document}
\setcounter{chapter}{3}
She stood silent for a minute, thinking: then she suddenly began again.
‘Then it really HAS happened, after all! And now, who am I? I WILL
remember, if I can! I’m determined to do it!’ But being determined
didn’t help much, and all she could say, after a great deal of puzzling,
was, ‘L, I KNOW it begins with L!’
Just then a Fawn came wandering by: it looked at Alice with its large
gentle eyes, but didn’t seem at all frightened. ‘Here then! Here then!’
Alice said, as she held out her hand and tried to stroke it; but it only
started back a little, and then stood looking at her again.
‘What do you call yourself?’ the Fawn said at last. Such a soft sweet
voice it had!
‘I wish I knew!’ thought poor Alice. She answered, rather sadly,
‘Nothing, just now.’
‘Think again,’ it said: ‘that won’t do.’
Alice thought, but nothing came of it. ‘Please, would you tell me
what YOU call yourself?’ she said timidly. ‘I think that might help a
little.’
‘I’ll tell you, if you’ll move a little further on,’ the Fawn said. ‘I
can’t remember here.’
So they walked on together though the wood, Alice with her arms clasped
lovingly round the soft neck of the Fawn, till they came out into
another open field, and here the Fawn gave a sudden bound into the air,
and shook itself free from Alice’s arms. ‘I’m a Fawn!’ it cried out in a
voice of delight, ‘and, dear me! you’re a human child!’ A sudden look of
alarm came into its beautiful brown eyes, and in another moment it had
darted away at full speed.
Alice stood looking after it, almost ready to cry with vexation at
having lost her dear little fellow-traveller so suddenly. ‘However, I
know my name now.’ she said, ‘that’s SOME comfort. Alice--Alice--I won’t
forget it again. And now, which of these finger-posts ought I to follow,
I wonder?’
It was not a very difficult question to answer, as there was only one
road through the wood, and the two finger-posts both pointed along it.
‘I’ll settle it,’ Alice said to herself, ‘when the road divides and they
point different ways.’
But this did not seem likely to happen. She went on and on, a long way,
but wherever the road divided there were sure to be two finger-posts
pointing the same way, one marked ‘TO TWEEDLEDUM’S HOUSE’ and the other
‘TO THE HOUSE OF TWEEDLEDEE.’
‘I do believe,’ said Alice at last, ‘that they live in the same house! I
wonder I never thought of that before--But I can’t stay there long. I’ll
just call and say “how d’you do?” and ask them the way out of the wood.
If I could only get to the Eighth Square before it gets dark!’ So she
wandered on, talking to herself as she went, till, on turning a sharp
corner, she came upon two fat little men, so suddenly that she could not
help starting back, but in another moment she recovered herself, feeling
sure that they must be.
%
\nowidow
\chapter{ Tweedledum And Tweedledee}
They were standing under a tree, each with an arm round the other’s
neck, and Alice knew which was which in a moment, because one of them
had ‘DUM’ embroidered on his collar, and the other ‘DEE.’ ‘I suppose
they’ve each got “TWEEDLE” round at the back of the collar,’ she said to
herself.
They stood so still that she quite forgot they were alive, and she was
just looking round to see if the word “TWEEDLE” was written at the back
of each collar, when she was startled by a voice coming from the one
marked ‘DUM.’
‘If you think we’re wax-works,’ he said, ‘you ought to pay, you know.
Wax-works weren’t made to be looked at for nothing, nohow!’
‘Contrariwise,’ added the one marked ‘DEE,’ ‘if you think we’re alive,
you ought to speak.’
‘I’m sure I’m very sorry,’ was all Alice could say; for the words of the
old song kept ringing through her head like the ticking of a clock, and
she could hardly help saying them out loud:--
They were standing under a tree, each with an arm round the other’s
neck, and Alice knew which was which in a moment, because one of them
had ‘DUM’ embroidered on his collar, and the other ‘DEE.’ ‘I suppose
they’ve each got “TWEEDLE” round at the back of the collar,’ she said to
herself.
They stood so still that she quite forgot they were alive, and she was
just looking round to see if the word “TWEEDLE” was written at the back
of each collar, when she was startled by a voice coming from the one
marked ‘DUM.’
‘If you think we’re wax-works,’ he said, ‘you ought to pay, you know.
Wax-works weren’t made to be looked at for nothing, nohow!’
‘Contrariwise,’ added the one marked ‘DEE,’ ‘if you think we’re alive,
you ought to speak.’
‘I’m sure I’m very sorry,’ was all Alice could say; for the words of the
old song kept ringing through her head like the ticking of a clock, and
she could hardly help saying them out loud:--
\end{document}
답변3
사용\enlargethispage
% ...
some text.
\enlargethispage{2\baselineskip}
more text
% ...
현재 페이지에 두 줄을 더 인쇄할 수 있습니다.