V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lsmgeb89
V2EX  ›  问与答

[LaTex] 在 section name 里自引用此 section 的 index

  •  
  •   lsmgeb89 · 2015-10-19 00:18:49 +08:00 · 3957 次点击
    这是一个创建于 3106 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Latex 新手,有个蛮特殊的需求, Google 了半天没查到。

    我想在 section name 里自引用此 section 的 index ,例如这个效果:

    1.1 This is Section 1.1

    PS :我已经用了 titlesec 包改了些样式,希望 solution 能不影响现在的设定,谢谢。
    \usepackage{titlesec}

    \titleformat{\subsection}{\normalfont\normalsize\itshape}{\thesubsection}{1em}{}
    \renewcommand\thesubsection{\thesection-\arabic{subsection}}
    第 1 条附言  ·  2015-10-19 10:32:29 +08:00
    参考这里找到了一个更好的办法:

    http://tex.stackexchange.com/questions/34702/get-reference-to-current-section

    不用 label 就可以,因为如果写 label 的话, marker 也相当于硬编码:

    \section{This is Section ~\thesection}
    3 条回复    2015-10-19 06:29:08 +08:00
    wsy2220
        1
    wsy2220  
       2015-10-19 01:43:38 +08:00
    这种事情我一般都是硬编码....
    或者用特殊标记, 编译前用别的工具批量替换
    wsy2220
        2
    wsy2220  
       2015-10-19 01:57:06 +08:00
    比如
    \subsection{This is Section ___ref}
    写个 python 脚本扫描一下这是第几个 section 和 subsection, 把___ref 替换成相应数字就好了.
    canautumn
        3
    canautumn  
       2015-10-19 06:29:08 +08:00   ❤️ 1
    用 cross reference 就可以吧,
    \subsection{This is Section \ref{subsec1}} \label{subsec1}
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   895 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:19 · PVG 05:19 · LAX 14:19 · JFK 17:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.