Forgot password?
 Create new account
View 1470|Reply 2

一切为了居中的公式别乱动

[Copy link]

700

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2018-1-19 17:52:36 |Read mode
问题来自:bbs.ctex.org/forum.php?mod=viewthread&tid=154820
1楼提问:
equation环境下,公式默认居中,但是加条件的公式会整体居中。现在希望公式居中,条件距离居中的公式有一定距离该怎么办呢?多谢!

7楼“XeTaL”答:
  1. \documentclass{article}
  2. \newcommand\tj[1]{\rlap{\quad$#1$}}
  3. \begin{document}
  4. \[  \pi_jx=x_j  \]
  5. \[  \pi_jx=x_j\tj{i \neq j}  \]
  6. \end{document}
Copy the Code
效果:
捕获.PNG

10楼搭车再问:
如此搭车请教一下各位高手,我想实现这样的排版效果,中间一个公式,比如简单点的a=b+c,现在想在左边加上内容,比如abc,这个abc想让它左边对齐到页面左边距,右边加上内容,比如def,这个def想让它右边对齐到页面右边距,本来想用\llap{abc\hspace*{\fill}}和\rlap{\hspace*{\fill}def},但测试没有效果。谢谢。

俺答:
  1. \documentclass[UTF8]{ctexart}
  2. \usepackage[showframe]{geometry}
  3. \usepackage{amsmath}
  4. \newcommand\lcr[3]{\vbox{%
  5. \noindent\rlap{#1}\hfill$\displaystyle#2$\hfill\llap{#3}%
  6. }}
  7. \begin{document}
  8. abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def
  9. \begin{gather*}
  10. a=b+c\\
  11. \lcr{abc}{a=b+c}{def}\\
  12. \lcr{中文来一个}{a=b+c}{xxoo}\\
  13. a=b+c\\
  14. a=b+c
  15. \end{gather*}
  16. \end{document}
Copy the Code
效果:
lcr.PNG

但是如果公式带编号会跑到下一行,于是再改:
  1. \documentclass[UTF8]{ctexart}
  2. \usepackage[showframe]{geometry}
  3. \usepackage{amsmath}
  4. \newcommand\lcr[3]{\makebox[0pt][c]{%将整个变成0宽,否则编号跑到下一行
  5. \vbox{%
  6. \noindent\rlap{#1}\hfill$\displaystyle#2$\hfill\llap{#3}%
  7. }}}
  8. \begin{document}
  9. abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def
  10. \begin{gather}
  11. a=b+c\\
  12. \lcr{abc}{a=b+c}{def}\notag\\
  13. \lcr{中文来一个}{a=b+c}{xxoo}\notag\\
  14. \lcr{编号一个}{a=b+c}{}\label{asdf}\\
  15. \lcr{再来}{a=b+c}{}\label{xxxx}\\
  16. a=b+c\\
  17. a=b+c
  18. \end{gather}
  19. 引用式 \eqref{asdf}、\eqref{xxxx}。
  20. \end{document}
Copy the Code
效果:
编号lcr.PNG

随后再问:
再提一个过分的要求,右侧有东西,也要编号,怎么处理
俺再答:
这…………直接加 \qquad 之类的空开好啦
如14楼第15行改成:\lcr{再来}{a=b+c}{1111\qquad}\label{xxxx}\\
如果一定要紧贴,那就:\lcr{再来}{a=b+c}{1111\hphantom{(\theequation)}}\label{xxxx}\\ ……
综上所述:
  1. \documentclass[UTF8]{ctexart}
  2. \usepackage[showframe]{geometry}
  3. \usepackage{amsmath}
  4. \newcommand\lcr[3]{\makebox[0pt][c]{%将整个变成0宽,否则编号跑到下一行
  5. \vbox{%
  6. \noindent\rlap{#1}\hfill$\displaystyle#2$\hfill\llap{#3}%
  7. }}}
  8. \begin{document}
  9. abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def
  10. \begin{gather}
  11. a=b+c\\
  12. \lcr{abc}{a=b+c}{def}\notag\\
  13. \lcr{中文来一个}{a=b+c}{xxoo}\notag\\
  14. \lcr{编号一个}{a=b+c}{}\label{asdf}\\
  15. \lcr{再来}{a=b+c}{这里也要\hphantom{(\theequation)}}\label{xxxx}\\
  16. a=b+c\\
  17. a=b+c
  18. \end{gather}
  19. 引用式 \eqref{asdf}、\eqref{xxxx}。
  20. \end{document}
Copy the Code
QQ截图20180119175853.png

801

Threads

4888

Posts

310K

Credits

Credits
36170

Show all posts

isee Posted at 2018-1-19 19:13:22
这种节约行路的排版像奇妙的搞法。。。。。

700

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

 Author| kuing Posted at 2018-1-19 21:31:34
可惜这种方法实现不了 align 这类环境中的。(我想起了之前看过的这帖:bbs.ctex.org/forum.php?mod=viewthread&tid=153976,该问题目前还没得到解决)

手机版Mobile version|Leisure Math Forum

2025-4-21 14:35 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list