Comments (4)
LaTeX 在执行到 \ifodd
时,还不知道自己要不要换页,所以 \value{page}
还是没换页时候的值。
应该告诉 LaTeX 还需要多少空间,在 LaTeX 决定要不要换页之后,才能得到想要的 \value{page}
。
\documentclass[fontset=windows,linespread=1.5625]{ctexart}
\usepackage[a4paper,twoside,top=35mm,bottom=35mm,left=28mm,right=26mm,showframe]{geometry}
\usepackage{zhlipsum}
\usepackage{needspace}
\newsavebox\makenotesbox
\newcommand{\makenotestext}
{\begin{tabular}[b]{l}
\hline
《史记·十二本纪·项羽本纪》 \\
\hline
\end{tabular}}
\newcommand{\makenotes}
{
\par
\sbox{\makenotesbox}{\parbox[b]{\textwidth}{\makenotestext}}
\needspace{%
\ifdim\dp\makenotesbox>\maxdepth
\dimexpr\ht\makenotesbox+\dp\makenotesbox-\maxdepth\relax
\else \ht\makenotesbox\fi}
\ifodd\value{page}
\ifdim\pagegoal=\maxdimen \hbox{}\thispagestyle{empty}\fi
\clearpage
\thispagestyle{empty}%
\hbox{}
\fi
% \null
% \vfill
\vspace*{\fill}
\noindent \usebox{\makenotesbox}\newpage
}
\begin{document}
\zihao{3}\fangsong
\zhlipsum[1-5][name=xiangyu]
\makenotes
\end{document}
from forum.
使用 \value{page}
获得的不一定是当前页数,于是对它的奇偶判断也会出错。比如,用在一个跨页的段落里时,不论插入 \value{page}
的位置对应输出后换页前还是换页后的部分,\value{page}
获得的总是换页前的页数。
这里需要「仅在 shipout/输出一页 时展开」,对应的就是 \write
(见 TeX by Topic, sec. 12.6.3 Expansion and \write
),缺点是需要第二次编译。这就是 ifoddpage
包封装的 \ifoddpage
。
PS:texlive 2023 开始,\special
获得了一个新的关键词 shipout
,\special shipout<general text>
可以和 \write
一样,仅在 shipout 时展开 <general text>
。详见 https://tug.org/texlive/doc/texlive-en/texlive-en.html#x1-920009.2 和 https://tex.stackexchange.com/q/681452 。
from forum.
在OP这种问题下,如果仅仅使用 \label
这类技术,最坏情况需要编译 n+1 次,而不是固定的两次吧,而且估计编译次数超过2次的概率比平时大。和 needspace 配合使用的话,当然是更好的选择。(除非取消某些页的 shipout,不用写入辅助文件的方式应该也行吧。)
\special
里好像不能放盒子?
from forum.
谢谢 @Sophanatprime 前辈提供的解决方案。
谢谢 @muzimuzhi 老师提供的信息,我好好研究一下。主要是本人的水平很菜,有些很简单的问题可能也需要很长时间看文档、搜索示例才能弄明白。汗!
from forum.
Related Issues (20)
- 讨论范围:CTeX套装问题or中文TeX问题? HOT 6
- Error: Undefined control sequence HOT 17
- 汉字直排行间标点下冒号(及分号)的问题 HOT 4
- xeCJK宏包文档中3.2.1节需要增补 HOT 4
- xeCJKfntef 和 ulem 联用时影响 \textbf 的作用范围 HOT 3
- 使用XeLatex构建中文文档源码时报错: xdvipdfmx:fatal: Unknown coverage format HOT 7
- 如何在article中调整所有caption为楷体 HOT 1
- linux和windows下伪粗效果不统一 HOT 6
- 中英文之间空格不习惯,如何去掉? HOT 11
- CJKfntef 是否具有 xeCJKfntef 的 subtract 功能?
- CTeX 3.0.212.1 xelatex编译通过,但无法生成pdf。dvipdfmx:fatal: typecheck: Invalid object type: -1 7 (line 2378)] HOT 6
- 关于LaTeX2e中文档类使用l3keys键对值的问题 HOT 8
- 当minipage环境和enumerate配合使用时,引入hyperref宏包会导致minipage顶部对齐失效 HOT 2
- 选项 leqno 与 fleqn 的缩写 HOT 13
- `jiazhu` 宏包是否能实现 `linespread < 1` 的排版效果?
- 如何将附录放在backmatter后同时对附录进行编号? HOT 6
- 能否实现英语句子中自动使用非中文字体的标点符号 HOT 3
- How to draw an specific feynman diagram with TikZ (LaTeX) HOT 4
- [NFSS] 关于使表示字体的控制序列等于\relax的作用(的问题) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forum.