【问题标题】:LaTeX: How to change one of section numbers to a custom letter?LaTeX:如何将节号之一更改为自定义字母?
【发布时间】:2010-05-15 09:43:37
【问题描述】:

我有这样的事情:

Section 1
...
Section 2
...
Section 3
Subsection 3.1
...
Section 4
...

我想要这样的东西:

Section 1
...
Section 2
...
Section A
Subsection A.1
...
Section 4
...

换句话说 - 将节号之一更改为其他 3 == A 我的论文需要这个,它写在文章类中,当我尝试添加附录时,hyperref 包损坏,并且“链接”到 第 1 节 指向 附录A

编辑: 我在描述问题时犯了一个错误,我的意思是 目录 不起作用,因为 LaTeX 生成代码(*.toc 文件):

\contentsline {section}{\numberline {1}}{1}{section.1}
\contentsline {section}{\numberline {2}}{1}{section.2}
\contentsline {section}{\numberline {A}}{1}{section.1}

【问题讨论】:

    标签: latex pdflatex


    【解决方案1】:

    我创建了以下构造,现在对其进行了更新

    说明

    一个新的节计数器,仅在 \begin{alphasection} ... \end{alphasection} 块中使用。不要嵌套块,否则原始节号会丢失; 在这种情况下会给出一条错误消息。每个块将从“A”开始重新计数。原始节计数继续进行,因为这是 HyperRef 所必需的。

    将以下代码放入序言

    \newcounter{alphasect}
    \def\alphainsection{0}
    
    \let\oldsection=\section
    \def\section{%
      \ifnum\alphainsection=1%
        \addtocounter{alphasect}{1}
      \fi%
    \oldsection}%
    
    \renewcommand\thesection{%
      \ifnum\alphainsection=1% 
        \Alph{alphasect}
      \else%
        \arabic{section}
      \fi%
    }%
    
    \newenvironment{alphasection}{%
      \ifnum\alphainsection=1%
        \errhelp={Let other blocks end at the beginning of the next block.}
        \errmessage{Nested Alpha section not allowed}
      \fi%
      \setcounter{alphasect}{0}
      \def\alphainsection{1}
    }{%
      \setcounter{alphasect}{0}
      \def\alphainsection{0}
    }%
    

    在文档中

    \section{First test}
    First content
    \section{Second test}
    Second content
    \begin{alphasection}
    \section{Third test}
    \subsection{Subsection test}
    Content test
    \section{Test Other section}
    \end{alphasection}
    \section{Fourth test}
    Last content
    

    生产

    1 First test
       First content
    
    2 Second test
       Second content
    
    A Third test
    A.1 Subsection test
       Content test
    
    B Test Other section
    
    5 Fourth test
       Last content
    

    经过测试,可与 HyperRef 配合使用。

    【讨论】:

    • 问题是hyperref包A1一样,所以section 1的链接直接到A 部分我需要一个命令来告诉 LaTeX 保持原始计数器运行但显示不同的值(在我的示例中 - 保持数字 3 但显示 A,保持数字 4 但显示 B)
    • @user309937 修复了问题 ;) 享受吧!
    【解决方案2】:

    给桑德拉, 使用上面的 Pindatjuh 代码时,我遇到了间距问题。它影响了所有列表。 我修复了它,在其代码的第三块的几行末尾添加了“%”。现在我没有间距了。

    发件人:

    \renewcommand\thesection{%
     \ifnum\alphainsection=1% 
       \Alph{alphasect}
     \else%
      \arabic{section}
     \fi%
    }%
    

    收件人:

    \renewcommand\thesection{%
     \ifnum\alphainsection=1% 
       \Alph{alphasect}%
     \else
       \arabic{section}%
     \fi%
    }%
    

    【讨论】:

      【解决方案3】:

      通过将选项 [naturalnames] 添加到 hyperref 包中,可以更轻松地解决 Karpik 遇到的问题(hyperref 问题): \usepackage[naturalnames]{hyperref}

      【讨论】:

        【解决方案4】:

        看看titlesec 包。

        【讨论】:

          【解决方案5】:

          好的,我使用@Pindatjuh 代码解决了它,解决方案非常丑陋...

           \newcounter{alphasect}
          
           \renewcommand\thesection{%
           \ifnum\value{alphasect}=1%
          A%%
           \else
          \ifnum\value{alphasect}=2%
          B%%
          \else
          \ifnum\value{alphasect}=3%
          C%%
          \else
          \ifnum\value{alphasect}=4%
          D%%
          \else
           \arabic{section}%%
           \fi\fi\fi\fi}%
          
           \newenvironment{asection}{%
           \setcounter{alphasect}{1}%%
           }{%
           \setcounter{alphasect}{0}%%
           }%
          
           \newenvironment{bsection}{%
           \setcounter{alphasect}{2}%%
           }{%
           \setcounter{alphasect}{0}%%
           }%
          

          比文档中的:

          \section{First test}
          First content
          \section{Second test}
          Second content
          \begin{asection}
          \section{Third test}
          \subsection{Subsection test}
          Content test
          \end{asection}
          \begin{bsection}
          \section{Test Other section}
          \end{bsection}
          \section{Fourth test}
          Last content
          

          现在内容列表可以正常工作,它应该显示出来

          【讨论】:

            猜你喜欢
            • 2019-05-26
            • 1970-01-01
            • 2020-09-30
            • 1970-01-01
            • 1970-01-01
            • 2011-10-04
            • 2020-07-11
            • 2013-05-21
            • 2023-04-04
            相关资源
            最近更新 更多