自訂詞彙表樣式:使詞彙表與 \textwidth 一樣寬

自訂詞彙表樣式:使詞彙表與 \textwidth 一樣寬

警告:這是一個後續問題顯示非首字母縮寫類型條目的長格式(類似首次使用)條目

作為馬夫普在另一篇文章中建議我繼續定義自己的術語表樣式(以及一些列說明符)來解決單位問題(使用欄位user1)。現在我的定義如下所示(tabx3col第一個術語表中使用的樣式和tabx4col第二個術語表中使用的樣式):

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newglossarystyle{tabx3col}{%
 % put the glossary in a longtable environment:
 \renewenvironment{theglossary}%
  {\begin{longtable}{L{0.2\textwidth}L{0.6\textwidth}R{0.2\textwidth}}}%
  {\end{longtable}}%
 % Set the table's header:
 \renewcommand*{\glossaryheader}{}%
 % No heading between groups:
  \renewcommand*{\glsgroupheading}[1]{}%
 % Main (level 0) entries displayed in a row:
  \renewcommand*{\glossaryentryfield}[5]{%
    \glstarget{##1}{\textbf{##2}}% Name
    & ##3% Description
    & ##5% Page list
    \\% end of row
  }%
 % Sub entries treated the same as level 0 entries:
 %\renewcommand*{\glossarysubentryfield}[6]{%
  %\glossaryentryfield{##2}{##3}{##5}{##6}}%
 %% Nothing between groups:
 %\renewcommand*{\glsgroupskip}{}%
}


\newglossarystyle{tabx4col}{%
 % put the glossary in a longtable environment:
 \renewenvironment{theglossary}%
  {\begin{longtable}{L{0.1\textwidth}L{0.1\textwidth}p{0.55\textwidth}R{0.2\textwidth}}}%
  {\end{longtable}}%
 % Set the table's header:
 \renewcommand*{\glossaryheader}{}%
 % No heading between groups:
  \renewcommand*{\glsgroupheading}[1]{}%
 % Main (level 0) entries displayed in a row:
  \renewcommand*{\glossaryentryfield}[5]{%
   \glstarget{\textbf{##1}}{\textbf{##2}}% Name
   & $[$\glsentryuseri{##1}$]$% Units
   & ##3% Description
   & ##5% Page list
    \\% end of row
  }%
 % Sub entries treated the same as level 0 entries:
 %\renewcommand*{\glossarysubentryfield}[6]{%
  %\glossaryentryfield{##2}{##3}{##5}{##6}}%
 %% Nothing between groups:
 %\renewcommand*{\glsgroupskip}{}%
}

這給了我一個輸出,如下圖: 輸出的螢幕截圖

我用一些灰線編輯了螢幕截圖,以顯示我想要對齊的文字(R對頁面列表中使用的固定寬度的 raggedright 列使用列說明符)。主要是我想要整個術語表\textwidth。我認為透過使每一列都依賴變數\textwidth並將值添加到 1,我會得到一個最終與標題一樣寬的表格。我還嘗試使用 tabularx 作為表環境,但失敗了(即使使用巨集命令,例如\tabularx \endtabularx )。我已經編譯了一個 MWE (http://pastebin.com/McqsTPga,也許不再那麼小了),您可以在其中親眼看到問題。

我很抱歉這篇文章有點長,但這確實困擾著我。

答案1

“我認為,通過使每一列都依賴變量\textwidth並將值添加到 1,我將得到一個最終與標題一樣寬的表格。”這幾乎是正確的,但是您忘記了自動新增的列間空間。您可以@{}使用列規範來抑制它。當我指定你的表格時

\newglossarystyle{tabx3col}{%
 \renewenvironment{theglossary}%
  {\begin{longtable}{@{}p{0.2\textwidth}@{}p{0.6\textwidth}@{}>{\raggedleft}p{0.2\textwidth}@{}}}%
  ...

\newglossarystyle{tabx4col}{%
 \renewenvironment{theglossary}%
  {\begin{longtable}{@{}p{0.12\textwidth}@{}p{0.08\textwidth}@{}p{0.6\textwidth}@{}>{\raggedleft}p{0.2\textwidth}@{}}}%
  ...

對齊效果如預期。最好不要抑制描述前後的列間空間。然後您必須將描述欄(或任何其他欄位)縮小 24pt。

答案2

\usepackage{calc}可以將longtable對齊方式指定為

\begin{longtable}{
  @{} % suppress the space at the left
  L{0.1\textwidth-\tabcolsep}
  L{0.1\textwidth-2\tabcolsep}
  p{0.6\textwidth-2\tabcolsep}
  R{0.2\textwidth-\tabcolsep}
  @{} % suppress the space at the right
}

您可能想要刪除最寬列中的列間空間;在這種情況下

\begin{longtable}{
  @{} % suppress the space at the left
  L{0.1\textwidth}
  L{0.1\textwidth}
  p{0.6\textwidth-6\tabcolsep}
  R{0.2\textwidth}
  @{} % suppress the space at the right
}

每列之前和之後都有一個\tabcolsep寬闊的空間;您有四列,因此,在抑制最左邊和最右邊的空格後,剩下六列。

相關內容