레이블을 사용하지 않고 하위 섹션 내에서 현재 섹션 제목을 어떻게 호출합니까?

레이블을 사용하지 않고 하위 섹션 내에서 현재 섹션 제목을 어떻게 호출합니까?

실습 매뉴얼을 작성하려고 합니다. 이 때문에 섹션 제목(활동 이름)으로 새 페이지 제목(헤더 아님)에 레이블을 지정하는 일관되고 일반화된 방법이 필요합니다.

\documentclass[12pt]{report}
\usepackage{nameref}
\usepackage{tabularx}
\newcolumntype{J}{>{\centering\arraybackslash}X}
\makeatletter
\newcommand*{\currentname}{\@currentlabelname}
\makeatother

\newcommand{\handinhead}{%
    \begin{center}
        \begin{table}[!h]
            \begin{tabularx}{\textwidth}{X J X}
                                 & \currentname &                  \\
                Name:~\hrulefill &              & Date:~\hrulefill \\
            \end{tabularx}
        \end{table}
    \end{center}
    \hrule
    }
\begin{Document}
\chapter{Lab Activities}    
\section{Lab1 Title}
        Here is the activity introduction.
        \subsection{Objective}
            Objective of the activity.
        \subsection{Equipment}
            A list of equipment needed.
        \subsection{Theory}
            Explanation of the theory.
\newpage
\handinhead
    The following is the hand in portion of the activity.

\end{document}

나는 해결책을 시도했다여기사용하여

\makeatletter
\newcommand*{\currentname}{\@currentlabelname}
\makeatother

하지만 섹션 제목 "Lab1 Title"을 반환해야 할 때 현재 하위 섹션 제목 "Theory"가 반환됩니다. 현재 Lable 1레벨을 올릴 수 있는 방법이 있나요?

답변1

\documentclass[12pt]{report}

\let\oldsection\section
\makeatletter
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred chapter can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\xdef\mysec{#2}\oldsection{#2}
}
\def\@StarredWithout#1{%
\xdef\mysec{#1}\oldsection*{#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\xdef\mysec{#2}\oldsection[#1]{#2}%
}
\def\@nonStarredWithout#1{%
\xdef\mysec{#1}\oldsection{#1}%
}
\makeatother

\begin{document}
\chapter{Lab Activities}    
\section{Lab1 Title}
        Here is the activity introduction.
        \subsection{Objective}
            Objective of the activity.
        \subsection{Equipment}
            A list of equipment needed.
        \subsection{Theory}
            Explanation of the theory.
\newpage
\hrule
Here we are in \mysec.
\hrule
The following is the hand in portion of the activity.



\end{document}

다음은 "라벨"을 전혀 사용하지 않는 방법입니다(요청한 대로).

출력을 확인하여 적합한지 확인하십시오.

(항상 \mysec마지막 섹션의 제목을 변수로 유지)

편집: (섹션 제목과 참조에서도 줄 바꿈을 허용합니다)

\let\oldsection\section
\makeatletter
\long\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred chapter can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\long\def\@StarredWith[#1]#2{%
\long\def\mysec{#2}\oldsection{#2}
}
\long\def\@StarredWithout#1{%
\long\def\mysec{#1}\oldsection*{#1}%
}
\long\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\long\def\@nonStarredWith[#1]#2{%
\long\def\mysec{#2}\oldsection[#1]{#2}%
}
\long\def\@nonStarredWithout#1{%
\long\def\mysec{#1}\oldsection{#1}%
}
\makeatother

답변2

\section제 생각에는 이름을 저장하고 새 섹션을 시작하는 래퍼를 만들 것 같습니다 . 선택적 인수를 허용하여 두 번째 부분에 대한 기존 매크로를 확장할 수도 있습니다. 이 경우에는 페이지 나누기가 뒤따르는 선택적 인수를 조판하도록 설정했습니다. 그렇지 않으면 페이지 나누기가 삽입되지 않습니다. 하지만 떼어내기 전에는 항상 휴식을 원하기 때문에 무조건 추가했습니다.

저는 이러한 종류의 사용이 일반적으로 상당히 구체적이고 맞춤형 매크로와 환경에서 이익을 얻는다는 것을 발견했습니다. 왜냐하면 기본적으로 저는 약간 다른 콘텐츠(다른 과제 이름, 다른 학생 ID, 다른 모듈)로 동일한 형식을 일관되게 반복하고 싶기 때문입니다. code .... 그래서 제가 가르치는 매크로는 반복적으로 필요하기 때문에 작업에 특화된 경향이 있습니다. 그런 다음 옵션을 사용하면 \section덜 구조화된 자료를 인터리브하려는 경우에도 사용할 수 있는 약간의 변형과 표준 매크로가 허용됩니다 .

나는 실제로 아마도 이것보다 훨씬 더 나아갈 것입니다 :-). 그러나 주행 거리는 항상 그렇듯 다양할 수 있습니다.

통사론:

  • \labsection[<short title>]{<title>}
  • \labsection{<title>}
  • \labsection*{<title>}
  • \handinhead[<text>]
  • \handinhead

\documentclass[12pt]{report}
\usepackage{tabularx,xparse}
\newcolumntype{J}{>{\centering\arraybackslash}X}
\newcommand*\labname{}
\NewDocumentCommand\labsection{som}{%
  \renewcommand*\labname{#3}%
  \IfBooleanTF{#1}{%
    \section*{#3}%
  }{%
    \IfValueTF{#2}{%
      \edef\tempa{#2}%
    }{%
      \edef\tempa{#3}%
    }%
    \section[\tempa]{#3}%
  }%
}
\NewDocumentCommand{\handinhead}{+o}{%
  \clearpage
  \begin{center}
    \begin{tabularx}{\textwidth}{X J X}
      & \labname &   \\
      Name:~\hrulefill & & Date:~\hrulefill \\
    \end{tabularx}
  \end{center}
  \hrule\medskip\par
  \IfValueT{#1}{#1\clearpage}%
}
\begin{document}
\chapter{Lab Activities}    
\labsection{Lab1 Title}
Here is the activity introduction.
\subsection{Objective}
Objective of the activity.
\subsection{Equipment}
A list of equipment needed.
\subsection{Theory}
Explanation of the theory.
\handinhead
[The following is the hand in portion of the activity.]

\labsection[Lab2]{Lab2 Title}
Here is the activity introduction.
\subsection{Objective}
Objective of the activity.
\subsection{Equipment}
A list of equipment needed.
\subsection{Theory}
Explanation of the theory.
\handinhead
The following is the hand in portion of the activity.

\labsection*[Lab3]{Lab3 Title}
Here is the activity introduction.
\subsection{Objective}
Objective of the activity.
\subsection{Equipment}
A list of equipment needed.
\subsection{Theory}
Explanation of the theory.
\handinhead
The following is the hand in portion of the activity.

\end{document}

5페이지의 실험실 활동

관련 정보