하위 섹션에서 LaTeX 오류 발생: 여기에 끝낼 줄이 없습니다.

하위 섹션에서 LaTeX 오류 발생: 여기에 끝낼 줄이 없습니다.

LaTeX 코드에는 다음과 같은 명령이 section있습니다 . subsection이러한 내용은 스타일 파일에 포함되어 있습니다 foo.cls.

\newenvironment{aside}{%
  \let\oldsection\section
  \renewcommand{\section}[1]{
    \par\vspace{\baselineskip}{\Large\headingfont\color{headercolor} ##1}
  }
  \begin{textblock}{3.6}(1.5, 4.33)
  \begin{flushright}
  \obeycr
}{%
  \restorecr
  \end{flushright}
  \end{textblock}
  \let\section\oldsection
}

\renewcommand{\section}[1]{
  \par\vspace{\parskip}
  {%
    \LARGE\headingfont\color{headercolor}%
    \@sectioncolor #1%
  }
  \par\vspace{\parskip}
}

\renewcommand{\subsection}[1]{
  \par\vspace{.5\parskip}%
  {\Large\headingfont\color{headercolor} #1}
  \par\vspace{.25\parskip}%
}

다음 설정에서 이 명령을 사용하려고 하면 오류가 발생했습니다.

\documentclass{foo}

\begin{document}
\begin{aside}
\section{foo}
bar
~
\section{foo}
\subsection{bar}
\end{aside}
\end{document}

특히 내가 겪고 있는 오류는 다음과 같습니다.

LaTeX Error: There's no line here to end.

l.55 \subsection{foo}

여기서 무슨 일이 일어나고 있나요?

답변1

당신이 보는 문제는 당신이 \obeycr. 의 효과는 (거의) 모든 입력 줄 끝에 \obeycr추가하는 것과 동일하므로 환경 내부에서는 다음을 입력한 것과 같습니다.\\aside

\section{foo}\\
bar\\
~\\
\section{foo}\\
\subsection{bar}\\

일반적인 상황에서 텍스트 본문에서 명령은 \\줄 바꿈을 의미합니다. 그러나 이 명령은 온전성 검사를 수행하고 끝낼 줄이 없을 때 오류를 발생시킵니다. 이것이 바로 여러분이 보는 오류입니다. 보다 구체적으로, \\수직 모드에서( a 이후 ) 명령을 사용하면 \par수직 모드에서는 줄바꿈을 할 수 없기 때문에 오류가 발생합니다. 해당 오류를 만드는 매우 빠른 방법은 다음과 같습니다.

\documentclass{article}
\begin{document}
\\
\end{document}

왜냐하면 문서가 시작될 때 TeX은 수직 모드이고 그 다음에는 \\. 오류를 수정하려면 \\.

하위 섹션 제목을 작성한 후 \subsection명령이 수행되고 (그리고 그 다음의 명령은 TeX의 모드를 변경하지 않음) 바로 뒤에 줄 끝(따라서 a)이 있기 때문에 정의에 오류가 표시됩니다. 그리고 우리는 이미 무슨 일이 일어나는지 알고 있습니다. 이 경우. 이 문제를 해결하려면 간단히 뒤에 주석 문자를 추가하면 됩니다 . 그러면 TeX는 줄 끝 문자를 삽입하지 않습니다.\par\vspace\\\subsection{bar}

이 문제를 해결하는 더 편리한 방법은 다음 \removecr명령을 정의 끝에 추가하는 것입니다 \subsection.

{\makeatletter\obeycr%
 \gdef\removecr{\@ifnextchar^^M{\@gobblecr}{}}%
 \def\@gobblecr^^M{}}

그런 다음 하나의(단 하나!) 줄 끝을 찾고, 발견되면 제거합니다.

다음은 컴파일 가능한 예입니다.

\documentclass{article}
{\makeatletter\obeycr%
 \gdef\removecr{\@ifnextchar^^M{\@gobblecr}{}}%
 \def\@gobblecr^^M{}}
\newenvironment{aside}{%
  \renewcommand{\section}[1]{%
    \par \vspace{\baselineskip}{\LARGE ##1}}%
  \renewcommand{\subsection}[1]{%
    \par \vspace{.5\parskip}%
      {\Large #1}%
    \par \vspace{.25\parskip}\removecr}
  \begin{flushright}%
    \obeycr
}{\end{flushright}}
\begin{document}
\begin{aside}
\section{foo}
bar
~
\section{foo}
\subsection{bar}
\end{aside}
\end{document}

가짜 공백을 생성하는 보호되지 않은 여러 줄 끝이 있다는 점도 참고하세요( %이를 제거하려면 줄 끝에 추가하세요). 또한 \section환경 종료 시 자동으로 복원되므로 정의를 저장할 필요가 없습니다 . 의 효과도 마찬가지입니다 \obeycr.

나는 당신을 강력히 추천합니다~하지 않다사용 \obeycr. 그것은 해결되는 것보다 더 많은 문제를 만들 것입니다. 또한 섹션을 재정의하는 방식으로 인해 LaTeX의 섹션 기능이 많이 손상됩니다.

관련 정보