
Estou tentando escrever um manual de laboratório. Por causa disso, preciso de um método consistente e generalizado para rotular um novo título de página (não o cabeçalho) com o título da seção (o nome da atividade).
\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}
Eu tentei as soluçõesAquiusando
\makeatletter
\newcommand*{\currentname}{\@currentlabelname}
\makeatother
mas isso retorna o título da subseção atual "Teoria" quando preciso retornar o título da seção "Título Lab1". Existe alguma maneira de aumentar o nível 1 da etiqueta atual?
Responder1
\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}
Aqui está uma maneira sem usar "rótulo" (como você pediu).
Verifique a saída para ver se está tudo bem para você.
(Mantendo sempre \mysec
variável o título da última seção)
Editar: (para permitir quebras de linha nos títulos das seções e também nas referências)
\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
Responder2
Eu criaria um wrapper para \section
, eu acho, que salva o nome e também inicia uma nova seção. Você também pode estender sua macro existente para a segunda parte, permitindo que ela receba um argumento opcional. Eu configurei as coisas para que, neste caso, ele componha o argumento opcional seguido por uma quebra de página. caso contrário, nenhuma quebra de página será inserida. Como você sempre quer uma pausa antes da parte de rasgar, acrescentei isso incondicionalmente.
Descobri que esse tipo de uso geralmente se beneficia de macros e ambientes bastante específicos e personalizados porque, basicamente, quero repetir o mesmo formato de forma consistente com conteúdo apenas ligeiramente diferente: um nome de tarefa diferente, uma carteira de aluno diferente, um módulo diferente código .... Portanto, minhas macros de ensino tendem a ser altamente específicas para tarefas porque preciso dessas coisas repetidamente. As opções permitem então pequenas variações e macros padrão, como as que \section
ainda estão disponíveis se eu quiser intercalar material menos estruturado.
Na verdade, eu provavelmente iria muito além disso :-). No entanto, os seus quilómetros podem, como sempre, variar.
Sintaxe:
\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}