繁體
|
簡體
Sclub交友聊天~加入聊天室當版主
(檢舉)
分享
新浪微博
QQ空间
人人网
腾讯微博
Facebook
Google+
Plurk
Twitter
Line
快速注册
登录
论坛
搜索
帮助
原始风格
brown
purple
green
red
orange
gray
pink
violet
blue
greyish-green
jeans
greenwall
私人消息 (0)
公共消息 (0)
系统消息 (0)
好友消息 (0)
帖子消息 (0)
应用通知 (0)
应用邀请 (0)
悠闲数学娱乐论坛(第2版)
»
TeX / LaTeX
» 请教例题编号时,能不能有多个层级?
返回列表
发帖
abababa
发短消息
加为好友
abababa
当前离线
UID
2354
帖子
1355
主题
285
精华
0
积分
7965
威望
11
阅读权限
90
在线时间
179 小时
注册时间
2014-5-1
最后登录
2022-5-14
1
#
跳转到
»
倒序看帖
打印
字体大小:
t
T
发表于 2020-12-7 13:33
|
只看该作者
请教例题编号时,能不能有多个层级?
如题。我打了一些例题,一般都是这样的层级:chapter -> section -> example,然后在定义时是这样的:
\newtheorem{example}{例}[section]
但有少数例题,就直接在chapter后面:chapter->example,这时编号就会像这样:例 1.0.1,表示第1章第1个例题,因为它没有section所以section变成0了,那能不能让它显示成“例1.1”这样呢?就是如果没有section时,就直接用chapter的编号加例题的编号
收藏
分享
分享到:
QQ空间
腾讯微博
腾讯朋友
kuing
发短消息
加为好友
kuing
当前离线
UID
1
帖子
8832
主题
619
精华
0
积分
66354
威望
113
阅读权限
200
性别
男
来自
广东广州
在线时间
21788 小时
注册时间
2013-6-13
最后登录
2024-3-9
2
#
发表于 2020-12-7 14:47
|
只看该作者
就是要去掉 .0 的 section ?那用个条件判断就好了
\documentclass[UTF8]{ctexbook}
\usepackage{amsthm}
\newtheorem{example}{例}[section]
\makeatletter
\renewcommand\theexample{%
\ifnum\c@section=0\relax
\thechapter.\arabic{example}%
\else
\thesection.\arabic{example}%
\fi}
\makeatother
\begin{document}
\chapter{A}
\begin{example}
无节
\end{example}
\begin{example}
无节
\end{example}
\section{A-a}
\begin{example}
有节
\end{example}
\begin{example}
有节
\end{example}
\section{A-b}
\begin{example}
有节
\end{example}
\begin{example}
有节
\end{example}
\end{document}
复制代码
$\href{https://kuingggg.github.io/}{\text{About Me}}$
TOP
kuing
发短消息
加为好友
kuing
当前离线
UID
1
帖子
8832
主题
619
精华
0
积分
66354
威望
113
阅读权限
200
性别
男
来自
广东广州
在线时间
21788 小时
注册时间
2013-6-13
最后登录
2024-3-9
3
#
发表于 2020-12-7 15:06
|
只看该作者
回复
2#
kuing
如果还需要处理其他的,比如引理定理命题什么的,每个都这样写就太麻烦了,干脆整一个命令来:
\documentclass[UTF8]{ctexbook}
\usepackage{amsthm}
\makeatletter
\newcommand\rmzosec[1]{%remove zero section
\expandafter\renewcommand\csname the#1\endcsname{%
\ifnum\c@section=0\relax
\thechapter.\arabic{#1}%
\else
\thesection.\arabic{#1}%
\fi}}
\makeatother
\newtheorem{example}{例}[section]
\newtheorem{thm}{定理}[section]
\rmzosec{example}
\rmzosec{thm}
\begin{document}
\chapter{A}
\begin{thm}
无节
\end{thm}
\begin{thm}
无节
\end{thm}
\begin{example}
无节
\end{example}
\begin{example}
无节
\end{example}
\section{A-a}
\begin{thm}
有节
\end{thm}
\begin{thm}
有节
\end{thm}
\begin{example}
有节
\end{example}
\begin{example}
有节
\end{example}
\section{A-b}
\begin{thm}
有节
\end{thm}
\begin{thm}
有节
\end{thm}
\begin{example}
有节
\end{example}
\begin{example}
有节
\end{example}
\end{document}
复制代码
$\href{https://kuingggg.github.io/}{\text{About Me}}$
TOP
abababa
发短消息
加为好友
abababa
当前离线
UID
2354
帖子
1355
主题
285
精华
0
积分
7965
威望
11
阅读权限
90
在线时间
179 小时
注册时间
2014-5-1
最后登录
2022-5-14
4
#
发表于 2020-12-7 18:17
|
只看该作者
回复
2#
kuing
谢谢,这个就很好用了,目前只有例题有这种情况,像引入似的举了几个例子,然后后面就进入分节了。
TOP
abababa
发短消息
加为好友
abababa
当前离线
UID
2354
帖子
1355
主题
285
精华
0
积分
7965
威望
11
阅读权限
90
在线时间
179 小时
注册时间
2014-5-1
最后登录
2022-5-14
5
#
发表于 2021-9-24 09:51
|
只看该作者
回复
2#
kuing
我突然发现这个新的,好像中间空了很大。
下载
(3.79 KB)
2021-9-24 09:48
前两个都是第0章无节的命题1,第一个没用这楼的设置,第二个用了这楼的设置,觉得汉字和数字之间的空白好像变大了。
后两个都是第1章第1节的例4,第一个没用设置,第二个用了设置,也是那个“例”和后面的数字之间的空白变大了。
这个能调吗?
TOP
kuing
发短消息
加为好友
kuing
当前离线
UID
1
帖子
8832
主题
619
精华
0
积分
66354
威望
113
阅读权限
200
性别
男
来自
广东广州
在线时间
21788 小时
注册时间
2013-6-13
最后登录
2024-3-9
6
#
发表于 2021-9-24 12:25
|
只看该作者
回复
5#
abababa
我用 3# 的代码来测试并没有出现这个问题,你用 3# 的整段代码试试看有没有问题,如果没有,那你给一段能重现问题的最小代码。
TOP
abababa
发短消息
加为好友
abababa
当前离线
UID
2354
帖子
1355
主题
285
精华
0
积分
7965
威望
11
阅读权限
90
在线时间
179 小时
注册时间
2014-5-1
最后登录
2022-5-14
7
#
发表于 2021-9-24 13:01
|
只看该作者
回复
6#
kuing
我用的是二楼的那个,示例代码如下,如果把那个“去掉无 section 的环境编号 0”下边那段用iffalse注释掉和不注释掉,就出现5楼的现象。
\documentclass[a4paper]{book}
\usepackage{amsmath,bm,yhmath,amssymb,etoolbox,esvect,stmaryrd,cite,enumitem,extarrows,mathtools,ifthen}
\usepackage{etoolbox}
%定理环境
\usepackage[amsmath, thmmarks]{ntheorem}
{
\theoremstyle{nonumberplain}
\theoremheaderfont{\indent\bfseries}
\theorembodyfont{\normalfont}
\theoremsymbol{\ensuremath{\Box}}
\newtheorem{proof}{证明}
}
\newtheorem{example}{例}[section]
\newcommand\exampleautorefname{例}
% 去掉无 section 的环境编号 0
\makeatletter
\renewcommand\theexample{
\ifnum\c@section=0\relax
\thechapter.\arabic{example}
\else
\thesection.\arabic{example}
\fi
}
\makeatother
\iffalse
\fi
\usepackage[pdfencoding=auto,psdextra,colorlinks,linkcolor=red,anchorcolor=blue,citecolor=blue]{hyperref}
% 字体
\usepackage[slantfont,boldfont]{xeCJK}
\punctstyle{kaiming}
\begin{document}
\chapter{first}
\begin{example}\label{exam01}
example01
\end{example}
ref\autoref{exam01}
\end{document}
复制代码
TOP
kuing
发短消息
加为好友
kuing
当前离线
UID
1
帖子
8832
主题
619
精华
0
积分
66354
威望
113
阅读权限
200
性别
男
来自
广东广州
在线时间
21788 小时
注册时间
2013-6-13
最后登录
2024-3-9
8
#
发表于 2021-9-24 13:39
|
只看该作者
回复
7#
abababa
那是因为你改了我的代码——请把你以为没用的三个 % 给补回去。
TOP
abababa
发短消息
加为好友
abababa
当前离线
UID
2354
帖子
1355
主题
285
精华
0
积分
7965
威望
11
阅读权限
90
在线时间
179 小时
注册时间
2014-5-1
最后登录
2022-5-14
9
#
发表于 2021-9-24 14:19
|
只看该作者
回复
8#
kuing
原来如此,我还以为注释后面什么也没有,就相当于没注释,没用呢。这是什么原理呢?
TOP
kuing
发短消息
加为好友
kuing
当前离线
UID
1
帖子
8832
主题
619
精华
0
积分
66354
威望
113
阅读权限
200
性别
男
来自
广东广州
在线时间
21788 小时
注册时间
2013-6-13
最后登录
2024-3-9
10
#
发表于 2021-9-24 14:47
|
只看该作者
回复
9#
abababa
\documentclass{article}
\begin{document}
xx
yy%
zz
\end{document}
复制代码
TOP
abababa
发短消息
加为好友
abababa
当前离线
UID
2354
帖子
1355
主题
285
精华
0
积分
7965
威望
11
阅读权限
90
在线时间
179 小时
注册时间
2014-5-1
最后登录
2022-5-14
11
#
发表于 2021-9-24 15:22
|
只看该作者
回复
10#
kuing
这是把那个换行符注释掉了吗,如果把那个命令写成一行,效果是一样的:
\renewcommand\theexample{\ifnum\c@section=0\relax\thechapter.\arabic{example}\else\thesection.\arabic{example}\fi
复制代码
所以猜是把换行注释了。
TOP
kuing
发短消息
加为好友
kuing
当前离线
UID
1
帖子
8832
主题
619
精华
0
积分
66354
威望
113
阅读权限
200
性别
男
来自
广东广州
在线时间
21788 小时
注册时间
2013-6-13
最后登录
2024-3-9
12
#
发表于 2021-9-24 15:36
|
只看该作者
回复
11#
abababa
是的,单个回车 = 空格。
不过,如果行末是命令,就没这问题,因为回车被命令吃掉了,所以我那代码就只有那三个地方需要 %
将 10# 的例子改成
\documentclass{article}
\newcommand\xx{xx}
\newcommand\yy{yy}
\newcommand\zz{zz}
\begin{document}
\xx
\yy
\zz
\end{document}
复制代码
TOP
abababa
发短消息
加为好友
abababa
当前离线
UID
2354
帖子
1355
主题
285
精华
0
积分
7965
威望
11
阅读权限
90
在线时间
179 小时
注册时间
2014-5-1
最后登录
2022-5-14
13
#
发表于 2021-9-24 17:51
|
只看该作者
回复
12#
kuing
这个不可见字符以前一直没注意,有些latex的文档里就有很多空白的%,以前还觉得奇怪,也没有注释加上有什么用,原来就是做这个用的。
TOP
返回列表
回复
发帖
[收藏此主题]
[关注此主题的新回复]
[通过 QQ、MSN 分享给朋友]