我在这里找到了一种定义我自己的词汇表风格的方法:
\newglossarystyle{superglossarystyle}
{
\setglossarystyle{super}
\renewenvironment{theglossary}
{
\tablehead{}
\tabletail{}
\begin{supertabular}{rp{\glsdescwidth}}
}
{
\end{supertabular}
}
}
%
\setglossarystyle{superglossarystyle}
如何在name
-field 中手动断行\newglossaryentry
?
现在的情况:
ParameterA,ParameterB This is the description of ParameterA and ParameterB,
that is long and automatically wraps.
ParameterC This is the description of ParameterC, that is long
and automatically wraps.
它看起来应该是这样的:
ParameterA,
ParameterB This is the description of ParameterA and ParameterB,
that is long and automatically wraps.
ParameterC This is the description of ParameterC, that is long
and automatically wraps.
我尝试添加\\,\linebreak,\tabbreak
“等”作为换行符,但没有成功。
\documentclass[pdftex,a4paper,oneside,12pt,halfparskip]{scrbook}
\usepackage[]{amsmath,amssymb}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3.6cm,bottom=3.6cm,left=3.6cm,right=3.6cm]{geometry}
\usepackage[]{glossaries}
\newglossarystyle{superglossarystyle}
{
\setglossarystyle{super}
\renewenvironment{theglossary}
{
\tablehead{}
\tabletail{}
\begin{supertabular}{cp{\glsdescwidth}}
}
{
\end{supertabular}
}
}
\setglossarystyle{superglossarystyle}
\makeglossaries
\newglossaryentry{pab}
{
name = {$\boldsymbol{ParameterA},\boldsymbol{ParameterB}$} ,
description = {This is the description of ParameterA and ParameterB, that is long and automatically wraps} ,
}
\newglossaryentry{pc}
{
name = {$\boldsymbol{ParameterC}$} ,
description = {This is the description of ParameterC, that is long and automatically wraps.} ,
}
\begin{document}
\glsaddallunused\printglossaries
\end{document}
答案1
标准列说明符为l
、r
和c
p{
长度}
。您可以使用array
包,但我认为在这种情况下不需要这样做,因为您可以使用 调整段落对齐方式\raggedleft
。定义新的词汇表样式时,考虑该样式的简化版本会有所帮助。在基本层面上,样式需要采用以下形式:
\documentclass{article}
\begin{document}
\begin{tabular}{p{2cm}p{4cm}}
\raggedleft A. & some text\\
\raggedleft AA. & some more text\\
\raggedleft AAA. & some more text
\end{tabular}
\end{document}
它具有右对齐的段落样式的第一列。
现在测试一下如果ParameterA,ParameterB
添加会发生什么:
\documentclass{article}
\begin{document}
\begin{tabular}{p{2cm}p{4cm}}
\raggedleft A. & some text\\
\raggedleft AA. & some more text\\
\raggedleft AAA. & some more text\\
\raggedleft ParameterA,ParameterB & some text
\end{tabular}
\end{document}
这没有换行,因为 TeX 无法插入换行符,所以结果相当丑陋。
相反,你需要为 TeX 提供一些范围来在逗号处断行:
\documentclass{article}
\newcommand{\comma}{,\penalty \exhyphenpenalty}
\begin{document}
\begin{tabular}{p{2cm}p{4cm}}
\raggedleft A. & some text\\
\raggedleft AA. & some more text\\
\raggedleft ParameterA\comma ParameterB & some text
\end{tabular}
\end{document}
TeX 现在可以打破这一行了:
2cm
这里我使用和硬编码了列宽4cm
,但glossaries
包为第二列定义了一个长度,称为\glsdescwidth
。您可以为第一列定义另一个长度:
\newlength\glsnamewidth
您需要根据文档的需要设置此值。例如:
\setlength{\glsnamewidth}{3cm}
或者
\setlength{\glsnamewidth}{0.3\hsize}
新的词汇表样式可以定义为:
\newglossarystyle{superglossarystyle}
{%
\setglossarystyle{super}%
\renewenvironment{theglossary}%
{%
\tablehead{}%
\tabletail{}%
\begin{supertabular}{p{\glsnamewidth}p{\glsdescwidth}}%
}%
{%
\end{supertabular}%
}%
\renewcommand{\glossentry}[2]{%
\raggedleft
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
}%
}
完整示例为:
\documentclass[pdftex,a4paper,oneside,12pt,halfparskip]{scrbook}
\usepackage[]{amsmath,amssymb}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3.6cm,bottom=3.6cm,left=3.6cm,right=3.6cm]{geometry}
\usepackage[]{glossaries}
\newcommand{\comma}{,\penalty \exhyphenpenalty}
\newlength\glsnamewidth
\setlength{\glsnamewidth}{0.3\hsize}
\newglossarystyle{superglossarystyle}
{%
\setglossarystyle{super}%
\renewenvironment{theglossary}%
{%
\tablehead{}%
\tabletail{}%
\begin{supertabular}{p{\glsnamewidth}p{\glsdescwidth}}%
}%
{%
\end{supertabular}%
}%
\renewcommand{\glossentry}[2]{%
\raggedleft
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
}%
}
\setglossarystyle{superglossarystyle}
\makeglossaries
\newglossaryentry{pab}
{
name =
{$\boldsymbol{ParameterA}\comma\boldsymbol{ParameterB}$} ,
description = {This is the description of ParameterA and
ParameterB, that is long and automatically wraps} ,
}
\newglossaryentry{pc}
{
name = {$\boldsymbol{ParameterC}$} ,
description = {This is the description of ParameterC, that is
long and automatically wraps.} ,
}
\begin{document}
\glsaddallunused\printglossaries
\end{document}
生成结果: