nomgroup 的 nomencl 中的換行符

nomgroup 的 nomencl 中的換行符

我使用 nomencl 來創建我的論文的命名法。
這篇論文由三章組成,我更喜歡為每一章都有一個單獨的清單。
我目前透過我的最小工作範例中的程式碼實現了這一點。
不幸的是,章節的名稱很長。因此它們不適合排成一行。

如何讓章節名稱在下一行繼續?
我怎麼能讓它以這樣的方式對齊,即第二行不是從頭開始(在“章節......”之下),而是在破折號之後的章節名稱之下(“一個相當長的標題......”) 。

\documentclass[a4paper,12pt]{book}
\usepackage[british,ngerman]{babel}
\usepackage{longtable} % longtable lets you have tables that span multiple pages

\usepackage{nomencl}
\makenomenclature
\renewcommand{\nomname}{List of Symbols}
\renewcommand{\nompreamble}{just some symbols}

\usepackage{etoolbox}
\renewcommand\nomgroup[1]{%
\item[\bfseries
\ifstrequal{#1}{A}{Common}{%
\ifstrequal{#1}{B}{Chapter 2 - A quite long title, a quite long title, a quite long title, a quite long title, a quite long title}{%
\ifstrequal{#1}{C}{Chapter 3 - A quite long title, a quite long title, a quite long title, a quite long title, a quite long title}{}}}%
]}

\begin{document}
\tableofcontents
\nomenclature[A,  1]{$\gamma$}{text} 
\nomenclature[A,  2]{$B$}{text}
\nomenclature[B,  1]{$\beta$}{text}
\nomenclature[B,  2]{$S$}{text}
\nomenclature[C,  1]{$\alpha$}{text}
\nomenclature[C,  2]{$\beta$}{text}
\printnomenclature[2cm]
\end{document}enter code here

答案1

我能夠用「parbox」解決問題:

   \usepackage{etoolbox}
   \renewcommand\nomgroup[1]{%
   \item[\bfseries
   \ifstrequal{#1}{A}{Common}{%
   \ifstrequal{#1}{B}{{\parbox[t]{16cm}{Chapter 2 - A quite long title, a quite long title, a quite long title, a quite long title, a quite long title}}}{%
   \ifstrequal{#1}{C}{{\parbox[t]{16cm}{Chapter 3 - A quite long title, a quite long title, a quite long title, a quite long title, a quite long title}}}{}}}%
   ]}

答案2

你的想法\parbox很好,但我建議進行一些改進,首先是避免猜測寬度。

\documentclass[a4paper,12pt]{book}
\usepackage[british,ngerman]{babel}

\usepackage{nomencl}
\usepackage{xparse}

\makenomenclature
\renewcommand{\nomname}{List of Symbols}
\renewcommand{\nompreamble}{just some symbols}

\newcommand{\nomA}{Common}
\newcommand{\nomB}{%
  \parbox[t]{\textwidth}{%
    Chapter 2 - A quite long title, a quite long title, a quite long title,
    a quite long title, a quite long title%
  }\kern-\labelsep
}
\newcommand{\nomC}{%
  \parbox[t]{\textwidth}{%
    Chapter 3 - A quite long title, a quite long title, a quite long title,
    a quite long title, a quite long title%
  }\kern-\labelsep
}
% this is easier than a long list of nested \ifstrequal calls and more easily scalable
\ExplSyntaxOn
\NewDocumentCommand{\nomgroupmake}{m}
 {
  \str_case:nnF { #1 }
   {
    {A}{\nomA}
    {B}{\nomB}
    {C}{\nomC}
   }
   {\ERROR}
 }
\ExplSyntaxOff

\renewcommand\nomgroup[1]{\item[\bfseries\nomgroupmake{#1}]}

\begin{document}

Some text to make the nomenclature appear
\nomenclature[A,1]{$\gamma$}{text} 
\nomenclature[A,2]{$B$}{text}
\nomenclature[B,1]{$\beta$}{text}
\nomenclature[B,2]{$S$}{text}
\nomenclature[C,1]{$\alpha$}{text}
\nomenclature[C,2]{$\beta$}{text}

\printnomenclature[2cm]

\end{document}

在此輸入影像描述

相關內容