我排版了一本包含问题和解决方案的书。我需要获取一个简短问题名称的列表。我期望会有类似于图片的方法:
\caption[Figure name for List of Figures]{Caption name}
以下是获取问题列表的方法的总结。
定理
这种方法似乎比其他方法更接近:
\documentclass{book}
\usepackage{ntheorem}
\theoremlisttype{all}
\newtheorem{Problem}{Problem}[chapter]
\begin{document}
\listtheorems{Problem}
\chapter{foo}
\begin{Problem}[Short foo name]
Foo!
\end{Problem}
\chapter{bar}
\begin{Problem}[Short bar name]
Bar!
\end{Problem}
\end{document}
- 这里的问题是,问题中也显示了短名称。也许可以定义一个新的
\newtheoremlisttype
...
thm工具
这是 MWE thmtools(来自https://tex.stackexchange.com/a/2500/8992)
\documentclass{book}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[numberwithin=chapter]{hypothesis}
\declaretheorem[numberwithin=chapter]{theorem}
\begin{document}
\renewcommand{\listtheoremname}{List of Hypotheses}
\listoftheorems[ignoreall,show={hypothesis}]
\chapter{foo}
\begin{hypothesis}[X-Y-relationship]
There is a positive relationship between X and Y.
\end{hypothesis}
\begin{theorem}
Some text.
\end{theorem}
\end{document}
- 无法为问题列表指定名称
黑客
以下是一些黑客攻击的 MWE(来自https://tex.stackexchange.com/a/6917/8992):
\documentclass{book}
\usepackage{ntheorem}
\newtheorem{hypo}{Hypothesis}[chapter]
\newtheorem{hypolist}{Hypothesis}[chapter]
\newcommand*\hypothesis[1]{%
\stepcounter{hypolist}%
\addtheoremline{hypolist}{#1}%
\begin{hypo}#1\end{hypo}
}
\begin{document}
\chapter*{List of Hypotheses}
\listtheorems{hypolist}
\chapter{foo}
\hypothesis{There is a positive relationship between $X$ and $Y$.}
\chapter{bar}
\hypothesis{There is a positive relationship between $X$ and $Z$.}
\hypothesis{There is a positive relationship between $Z$ and $Y$.}
\end{document}
- 无法为问题列表指定一个较短的名称
答案1
您可以简单地重新定义plain
定理样式以忽略“归因”部分。默认定义是
\newtheoremstyle{plain}
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]}
所以你可以说
\documentclass{book}
\usepackage{ntheorem}
\theoremlisttype{all}
\makeatletter
\newtheoremstyle{problem}
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}
\makeatother
\theoremstyle{problem}
\newtheorem{Problem}{Problem}[chapter]
\begin{document}
\chapter*{List of problems}
\listtheorems{Problem}
\chapter{foo}
\begin{Problem}[Short foo name]
Foo!
\end{Problem}
\chapter{bar}
\begin{Problem}[Short bar name]
Bar!
\end{Problem}
\end{document}
以下是列表:
这是第一个问题文本
答案2
对于这种情况,我会倾向于定义自己的包environment
,而不是侵入现有包的内部。
在下面的代码中,我定义了两个环境供您使用,具体取决于您的需要。这两种方法都依赖于etoolbox
对于一些命令-第二个环境需要xparse
对于具有两个可选参数的环境。
两个环境都添加到\jobname.prb
使用命令创建的环境\@starttoc
。
问题
.prb
该环境采用可选参数,如果不为空,则会添加到该参数中。
% define the Problem environment
%
% Takes an optional description- if it is not empty,
% then it is added to \jobname.prb
\newcounter{problem}
\newenvironment{problem}[1][]{\refstepcounter{problem}%
{\bfseries Problem~\theproblem} %
\ifstrempty{#1}%
{%
% if #1 is empty, do nothing
}%
{%
% otherwise add it to jobname.prb
\addcontentsline{prb}{subsection}{#1}%
}%
}{}
这可以用作
\begin{problem}
\lipsum[2]
\end{problem}
或者
\begin{problem}[Description goes here, and added to jobname.prb]
\lipsum[2]
\end{problem}
其他问题
这个有点复杂,因为它需要二可选参数。
% define another Problem environment, just for demonstration
%
% Takes TWO optional arguments:
% #1: long description, used for \jobname.prb if #2 is not present
% #2: short description, used for \jobname.prb if present
\newcounter{otherproblem}
\NewDocumentEnvironment{otherproblem}{O{} O{}}{\refstepcounter{otherproblem}%
{\bfseries Problem~\theotherproblem} %
\ifstrempty{#2}%
{%
% if #2 is empty, then check for #1, and
% use it for jobname.prb if present
\ifstrempty{#1}%
{%
% if #1 is empty, do nothing
}%
{%
% otherwise, display it, and add it to
% \jobname.prb
{[\bfseries #1]}%
\addcontentsline{prb}{subsection}{#1}%
}%
}%
{%
% if #2 is not empty, use it for the
% \jobname.prb
\addcontentsline{prb}{subsection}{#2}%
\ifstrempty{#1}%
{}%
{%
{[\bfseries #1]}%
}%
}%
}{}
示例用法
\begin{otherproblem}[Long description][Short description for list]
\lipsum[2]
\end{otherproblem}
或者
\begin{otherproblem}[Long description displayed and added to list]
\lipsum[2]
\end{otherproblem}
或者
\begin{otherproblem}[][Short description for list, nothing displayed]
\lipsum[2]
\end{otherproblem}
这是完整的 MWE,可供使用 - 如果您需要帮助改变style
环境,请告诉我。
\documentclass{article}
\usepackage{lipsum}% just to generate text
\usepackage{etoolbox}
\usepackage{xparse}
% this sets up \jobname.prb which will store the
% contentslines added on each problem
\makeatletter
\newcommand\listproblemname{List of problems}
\newcommand\listofproblems{%
\section*{\listproblemname}\@starttoc{prb}}
\makeatother
% define the Problem environment
%
% Takes an optional description- if it is not empty,
% then it is added to \jobname.prb
\newcounter{problem}
\newenvironment{problem}[1][]{\refstepcounter{problem}%
{\bfseries Problem~\theproblem} %
\ifstrempty{#1}%
{%
% if #1 is empty, do nothing
}%
{%
% otherwise add it to jobname.prb
\addcontentsline{prb}{subsection}{#1}%
}%
}{}
% define another Problem environment, just for demonstration
%
% Takes TWO optional arguments:
% #1: long description, used for \jobname.prb if #2 is not present
% #2: short description, used for \jobname.prb if present
\newcounter{otherproblem}
\NewDocumentEnvironment{otherproblem}{O{} O{}}{\refstepcounter{otherproblem}%
{\bfseries Problem~\theotherproblem} %
\ifstrempty{#2}%
{%
% if #2 is empty, then check for #1, and
% use it for jobname.prb if present
\ifstrempty{#1}%
{%
% if #1 is empty, do nothing
}%
{%
% otherwise, display it, and add it to
% \jobname.prb
{[\bfseries #1]}%
\addcontentsline{prb}{subsection}{#1}%
}%
}%
{%
% if #2 is not empty, use it for the
% \jobname.prb
\addcontentsline{prb}{subsection}{#2}%
\ifstrempty{#1}%
{}%
{%
{[\bfseries #1]}%
}%
}%
}{}
\begin{document}
\listofproblems
\clearpage
\begin{problem}[Regular problem environment]
\lipsum[1]
\end{problem}
\begin{otherproblem}[Long description][Short description for list]
\lipsum[2]
\end{otherproblem}
\begin{problem}
\lipsum[2]
\end{problem}
\begin{problem}
\lipsum[2]
\end{problem}
\end{document}