├── .gitignore ├── LICENSE ├── README.md ├── book_cover.png ├── book_cover.tex ├── figures ├── box-parameters.png ├── cmidline.png ├── color_table.png ├── colorbox.png ├── enumerate_1.png ├── enumerate_2.png ├── fcolorbox.png ├── geometry-option-one.png ├── geometry-option-two.png ├── glue.png ├── ju-li-shi-jian-qu-xian-tu.png ├── line.png ├── multicolumn.png ├── multicolumn_2.png ├── notecard.png ├── scale_table.png ├── self_define_command_1.png ├── siunitx_1.png ├── siunitx_2.png ├── siunitx_3.png ├── siunitx_4.png ├── tcolorbox.png ├── temp.jpg ├── ubuntu_font_show.png ├── ubuntu_logo_font.png ├── vbox_show.png ├── wendu.png ├── xcolor.png └── xcolor_mix.png ├── main.tex ├── mybook.sty ├── mybookcover.sty └── 配置参考 ├── book_cover ├── book_cover.png ├── book_cover.tex ├── book_cover_ref.png └── book_cover_ref.tex ├── epub ├── epub.css └── epub.yaml ├── mybook.sty ├── mybookcover.sty ├── pdf_book.tex └── pdf_paper.tex /.gitignore: -------------------------------------------------------------------------------- 1 | *.acn 2 | *.acr 3 | *.alg 4 | *.aux 5 | *.bbl 6 | *.blg 7 | *.dvi 8 | *.fdb_latexmk 9 | *.glg 10 | *.glo 11 | *.gls 12 | *.idx 13 | *.ilg 14 | *.ind 15 | *.ist 16 | *.lof 17 | *.log 18 | *.lot 19 | *.maf 20 | *.mtc 21 | *.mtc0 22 | *.nav 23 | *.nlo 24 | *.out 25 | *.pdfsync 26 | *.ps 27 | *.snm 28 | *.synctex.gz 29 | *.toc 30 | *.vrb 31 | *.xdy 32 | *.tdo 33 | *.ent 34 | 35 | 36 | *.epub 37 | *.pdf 38 | *.tex.bak 39 | _minted/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution 4.0 International Public License 58 | 59 | By exercising the Licensed Rights (defined below), You accept and agree 60 | to be bound by the terms and conditions of this Creative Commons 61 | Attribution 4.0 International Public License ("Public License"). To the 62 | extent this Public License may be interpreted as a contract, You are 63 | granted the Licensed Rights in consideration of Your acceptance of 64 | these terms and conditions, and the Licensor grants You such rights in 65 | consideration of benefits the Licensor receives from making the 66 | Licensed Material available under these terms and conditions. 67 | 68 | 69 | Section 1 -- Definitions. 70 | 71 | a. Adapted Material means material subject to Copyright and Similar 72 | Rights that is derived from or based upon the Licensed Material 73 | and in which the Licensed Material is translated, altered, 74 | arranged, transformed, or otherwise modified in a manner requiring 75 | permission under the Copyright and Similar Rights held by the 76 | Licensor. For purposes of this Public License, where the Licensed 77 | Material is a musical work, performance, or sound recording, 78 | Adapted Material is always produced where the Licensed Material is 79 | synched in timed relation with a moving image. 80 | 81 | b. Adapter's License means the license You apply to Your Copyright 82 | and Similar Rights in Your contributions to Adapted Material in 83 | accordance with the terms and conditions of this Public License. 84 | 85 | c. Copyright and Similar Rights means copyright and/or similar rights 86 | closely related to copyright including, without limitation, 87 | performance, broadcast, sound recording, and Sui Generis Database 88 | Rights, without regard to how the rights are labeled or 89 | categorized. For purposes of this Public License, the rights 90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 91 | Rights. 92 | 93 | d. Effective Technological Measures means those measures that, in the 94 | absence of proper authority, may not be circumvented under laws 95 | fulfilling obligations under Article 11 of the WIPO Copyright 96 | Treaty adopted on December 20, 1996, and/or similar international 97 | agreements. 98 | 99 | e. Exceptions and Limitations means fair use, fair dealing, and/or 100 | any other exception or limitation to Copyright and Similar Rights 101 | that applies to Your use of the Licensed Material. 102 | 103 | f. Licensed Material means the artistic or literary work, database, 104 | or other material to which the Licensor applied this Public 105 | License. 106 | 107 | g. Licensed Rights means the rights granted to You subject to the 108 | terms and conditions of this Public License, which are limited to 109 | all Copyright and Similar Rights that apply to Your use of the 110 | Licensed Material and that the Licensor has authority to license. 111 | 112 | h. Licensor means the individual(s) or entity(ies) granting rights 113 | under this Public License. 114 | 115 | i. Share means to provide material to the public by any means or 116 | process that requires permission under the Licensed Rights, such 117 | as reproduction, public display, public performance, distribution, 118 | dissemination, communication, or importation, and to make material 119 | available to the public including in ways that members of the 120 | public may access the material from a place and at a time 121 | individually chosen by them. 122 | 123 | j. Sui Generis Database Rights means rights other than copyright 124 | resulting from Directive 96/9/EC of the European Parliament and of 125 | the Council of 11 March 1996 on the legal protection of databases, 126 | as amended and/or succeeded, as well as other essentially 127 | equivalent rights anywhere in the world. 128 | 129 | k. You means the individual or entity exercising the Licensed Rights 130 | under this Public License. Your has a corresponding meaning. 131 | 132 | 133 | Section 2 -- Scope. 134 | 135 | a. License grant. 136 | 137 | 1. Subject to the terms and conditions of this Public License, 138 | the Licensor hereby grants You a worldwide, royalty-free, 139 | non-sublicensable, non-exclusive, irrevocable license to 140 | exercise the Licensed Rights in the Licensed Material to: 141 | 142 | a. reproduce and Share the Licensed Material, in whole or 143 | in part; and 144 | 145 | b. produce, reproduce, and Share Adapted Material. 146 | 147 | 2. Exceptions and Limitations. For the avoidance of doubt, where 148 | Exceptions and Limitations apply to Your use, this Public 149 | License does not apply, and You do not need to comply with 150 | its terms and conditions. 151 | 152 | 3. Term. The term of this Public License is specified in Section 153 | 6(a). 154 | 155 | 4. Media and formats; technical modifications allowed. The 156 | Licensor authorizes You to exercise the Licensed Rights in 157 | all media and formats whether now known or hereafter created, 158 | and to make technical modifications necessary to do so. The 159 | Licensor waives and/or agrees not to assert any right or 160 | authority to forbid You from making technical modifications 161 | necessary to exercise the Licensed Rights, including 162 | technical modifications necessary to circumvent Effective 163 | Technological Measures. For purposes of this Public License, 164 | simply making modifications authorized by this Section 2(a) 165 | (4) never produces Adapted Material. 166 | 167 | 5. Downstream recipients. 168 | 169 | a. Offer from the Licensor -- Licensed Material. Every 170 | recipient of the Licensed Material automatically 171 | receives an offer from the Licensor to exercise the 172 | Licensed Rights under the terms and conditions of this 173 | Public License. 174 | 175 | b. No downstream restrictions. You may not offer or impose 176 | any additional or different terms or conditions on, or 177 | apply any Effective Technological Measures to, the 178 | Licensed Material if doing so restricts exercise of the 179 | Licensed Rights by any recipient of the Licensed 180 | Material. 181 | 182 | 6. No endorsement. Nothing in this Public License constitutes or 183 | may be construed as permission to assert or imply that You 184 | are, or that Your use of the Licensed Material is, connected 185 | with, or sponsored, endorsed, or granted official status by, 186 | the Licensor or others designated to receive attribution as 187 | provided in Section 3(a)(1)(A)(i). 188 | 189 | b. Other rights. 190 | 191 | 1. Moral rights, such as the right of integrity, are not 192 | licensed under this Public License, nor are publicity, 193 | privacy, and/or other similar personality rights; however, to 194 | the extent possible, the Licensor waives and/or agrees not to 195 | assert any such rights held by the Licensor to the limited 196 | extent necessary to allow You to exercise the Licensed 197 | Rights, but not otherwise. 198 | 199 | 2. Patent and trademark rights are not licensed under this 200 | Public License. 201 | 202 | 3. To the extent possible, the Licensor waives any right to 203 | collect royalties from You for the exercise of the Licensed 204 | Rights, whether directly or through a collecting society 205 | under any voluntary or waivable statutory or compulsory 206 | licensing scheme. In all other cases the Licensor expressly 207 | reserves any right to collect such royalties. 208 | 209 | 210 | Section 3 -- License Conditions. 211 | 212 | Your exercise of the Licensed Rights is expressly made subject to the 213 | following conditions. 214 | 215 | a. Attribution. 216 | 217 | 1. If You Share the Licensed Material (including in modified 218 | form), You must: 219 | 220 | a. retain the following if it is supplied by the Licensor 221 | with the Licensed Material: 222 | 223 | i. identification of the creator(s) of the Licensed 224 | Material and any others designated to receive 225 | attribution, in any reasonable manner requested by 226 | the Licensor (including by pseudonym if 227 | designated); 228 | 229 | ii. a copyright notice; 230 | 231 | iii. a notice that refers to this Public License; 232 | 233 | iv. a notice that refers to the disclaimer of 234 | warranties; 235 | 236 | v. a URI or hyperlink to the Licensed Material to the 237 | extent reasonably practicable; 238 | 239 | b. indicate if You modified the Licensed Material and 240 | retain an indication of any previous modifications; and 241 | 242 | c. indicate the Licensed Material is licensed under this 243 | Public License, and include the text of, or the URI or 244 | hyperlink to, this Public License. 245 | 246 | 2. You may satisfy the conditions in Section 3(a)(1) in any 247 | reasonable manner based on the medium, means, and context in 248 | which You Share the Licensed Material. For example, it may be 249 | reasonable to satisfy the conditions by providing a URI or 250 | hyperlink to a resource that includes the required 251 | information. 252 | 253 | 3. If requested by the Licensor, You must remove any of the 254 | information required by Section 3(a)(1)(A) to the extent 255 | reasonably practicable. 256 | 257 | 4. If You Share Adapted Material You produce, the Adapter's 258 | License You apply must not prevent recipients of the Adapted 259 | Material from complying with this Public License. 260 | 261 | 262 | Section 4 -- Sui Generis Database Rights. 263 | 264 | Where the Licensed Rights include Sui Generis Database Rights that 265 | apply to Your use of the Licensed Material: 266 | 267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 268 | to extract, reuse, reproduce, and Share all or a substantial 269 | portion of the contents of the database; 270 | 271 | b. if You include all or a substantial portion of the database 272 | contents in a database in which You have Sui Generis Database 273 | Rights, then the database in which You have Sui Generis Database 274 | Rights (but not its individual contents) is Adapted Material; and 275 | 276 | c. You must comply with the conditions in Section 3(a) if You Share 277 | all or a substantial portion of the contents of the database. 278 | 279 | For the avoidance of doubt, this Section 4 supplements and does not 280 | replace Your obligations under this Public License where the Licensed 281 | Rights include other Copyright and Similar Rights. 282 | 283 | 284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 285 | 286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 296 | 297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 306 | 307 | c. The disclaimer of warranties and limitation of liability provided 308 | above shall be interpreted in a manner that, to the extent 309 | possible, most closely approximates an absolute disclaimer and 310 | waiver of all liability. 311 | 312 | 313 | Section 6 -- Term and Termination. 314 | 315 | a. This Public License applies for the term of the Copyright and 316 | Similar Rights licensed here. However, if You fail to comply with 317 | this Public License, then Your rights under this Public License 318 | terminate automatically. 319 | 320 | b. Where Your right to use the Licensed Material has terminated under 321 | Section 6(a), it reinstates: 322 | 323 | 1. automatically as of the date the violation is cured, provided 324 | it is cured within 30 days of Your discovery of the 325 | violation; or 326 | 327 | 2. upon express reinstatement by the Licensor. 328 | 329 | For the avoidance of doubt, this Section 6(b) does not affect any 330 | right the Licensor may have to seek remedies for Your violations 331 | of this Public License. 332 | 333 | c. For the avoidance of doubt, the Licensor may also offer the 334 | Licensed Material under separate terms or conditions or stop 335 | distributing the Licensed Material at any time; however, doing so 336 | will not terminate this Public License. 337 | 338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 339 | License. 340 | 341 | 342 | Section 7 -- Other Terms and Conditions. 343 | 344 | a. The Licensor shall not be bound by any additional or different 345 | terms or conditions communicated by You unless expressly agreed. 346 | 347 | b. Any arrangements, understandings, or agreements regarding the 348 | Licensed Material not stated herein are separate from and 349 | independent of the terms and conditions of this Public License. 350 | 351 | 352 | Section 8 -- Interpretation. 353 | 354 | a. For the avoidance of doubt, this Public License does not, and 355 | shall not be interpreted to, reduce, limit, restrict, or impose 356 | conditions on any use of the Licensed Material that could lawfully 357 | be made without permission under this Public License. 358 | 359 | b. To the extent possible, if any provision of this Public License is 360 | deemed unenforceable, it shall be automatically reformed to the 361 | minimum extent necessary to make it enforceable. If the provision 362 | cannot be reformed, it shall be severed from this Public License 363 | without affecting the enforceability of the remaining terms and 364 | conditions. 365 | 366 | c. No term or condition of this Public License will be waived and no 367 | failure to comply consented to unless expressly agreed to by the 368 | Licensor. 369 | 370 | d. Nothing in this Public License constitutes or may be interpreted 371 | as a limitation upon, or waiver of, any privileges and immunities 372 | that apply to the Licensor or You, including from the legal 373 | processes of any jurisdiction or authority. 374 | 375 | 376 | ======================================================================= 377 | 378 | Creative Commons is not a party to its public licenses. 379 | Notwithstanding, Creative Commons may elect to apply one of its public 380 | licenses to material it publishes and in those instances will be 381 | considered the “Licensor.” The text of the Creative Commons public 382 | licenses is dedicated to the public domain under the CC0 Public Domain 383 | Dedication. Except for the limited purpose of indicating that material 384 | is shared under a Creative Commons public license or as otherwise 385 | permitted by the Creative Commons policies published at 386 | creativecommons.org/policies, Creative Commons does not authorize the 387 | use of the trademark "Creative Commons" or any other trademark or logo 388 | of Creative Commons without its prior written consent including, 389 | without limitation, in connection with any unauthorized modifications 390 | to any of its public licenses or any other arrangements, 391 | understandings, or agreements concerning use of licensed material. For 392 | the avoidance of doubt, this paragraph does not form part of the public 393 | licenses. 394 | 395 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## XeLaTeX 指南 2 | 3 | XeLaTeX 指南 4 | 5 | 6 | ## TODO 7 | 数学公式输入那块以后可能会再增加一些吧。 8 | 9 | tikz制图想过,有些地方简单的tikz制图还是很方便的,但还是手绘方便些,个人时间精力有限。那些需要出版级别的制图效果的集中精力学学还是很有用的。 10 | 11 | Tex高级命令篇,至少一些最基本最核心的命令,怎么编写宏包,也想过。但Tex作为编程语言实在一言难尽,有编程需求还是外面跑其他脚本运行吧。 12 | 13 | 暂时先这样吧。 14 | 15 | ## 更新日志 16 | ### 20250404 17 | 1. 只关注于本地pdf文件输出,移除了epub输出支持 18 | 2. Texlive升级到2025版,似乎没有影响 19 | 3. 结构精简,移除了一些不常用的内容 20 | 4. 更加关注数学公式输出那一块,全面重写 21 | 22 | 23 | ### 20201120 24 | 25 | ulem的uline命令不知道什么时候起不能正常中文换行了,通过引入`xeCJKfntef`宏包问题得到解决。 26 | 27 | ### 20200816 28 | 29 | 楷体更改为授权更宽松的 `台湾全字库正楷体` 。 30 | 31 | ### 第四次修订版 32 | 33 | 1. 引入epub书籍兼容制作流程。 34 | 2. Texlive升级到2020版,有一两处小bug,已修复。 35 | 3. 其他问题完善 36 | 37 | ### 第三次修订版 38 | 39 | 数学模式内容极大丰富和完善。 40 | 41 | 42 | 43 | ## 补充信息 44 | 临时有些补充信息就先方便放在readme这里了。 45 | 46 | 47 | 48 | ### tikz制图 49 | tikz制图专门做了一个gallery项目,请点击 [这里](https://github.com/a358003542/tikz_gallery)。 50 | 51 | ### 字体推荐 52 | 53 | 现在 google 和adobe 合作开发的开源字体 思源宋体和思源黑体很火,推荐使用这两个字体,效果还是不错的。读者可以到他们的 [官网](https://source.typekit.com/source-han-serif/cn/) 上看一下,github地址在 [这里](https://github.com/adobe-fonts/source-han-serif) ,不过下载要1G多,也可以到 [百度网盘这里](https://pan.baidu.com/s/1smo7EMD) 下载,这是我整理的一些字体。具体配置如下: 54 | 55 | ```latex 56 | \setCJKmainfont[ItalicFont=方正楷体简体]{思源宋体 CN} 57 | \setCJKsansfont{思源黑体 CN} 58 | \setCJKmonofont{方正楷体简体} 59 | ``` 60 | 61 | 其中思源宋体 CN没有italic shape,如上指定为方正楷体简体,方正楷体简体也是开源的。经过试验效果还是挺好的,整个字体给人的感觉简约大气。经过编译还有一个warning:没有sc shape,什么small caps 字形,这个思源宋体 CN也没有,但那个small caps字形太不常用了,所以不用管也是可以的。 62 | 63 | **windows 下安装字体记得点击为所有用户安装,新安装字体没发现后来折腾了好久,最后发现是没有选择为所有用户安装。xetex是能够自动使用系统安装好了的字体的,然后记得运行下 fc-cache即可。** 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /book_cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/book_cover.png -------------------------------------------------------------------------------- /book_cover.tex: -------------------------------------------------------------------------------- 1 | \documentclass[12pt,oneside]{book} 2 | 3 | \usepackage{mybook} 4 | \usepackage{mybookcover} 5 | 6 | 7 | \begin{document} 8 | 9 | \title{XeLaTeX指南} 10 | \author{Wander} 11 | 12 | \makemytitle 13 | 14 | \end{document} -------------------------------------------------------------------------------- /figures/box-parameters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/box-parameters.png -------------------------------------------------------------------------------- /figures/cmidline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/cmidline.png -------------------------------------------------------------------------------- /figures/color_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/color_table.png -------------------------------------------------------------------------------- /figures/colorbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/colorbox.png -------------------------------------------------------------------------------- /figures/enumerate_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/enumerate_1.png -------------------------------------------------------------------------------- /figures/enumerate_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/enumerate_2.png -------------------------------------------------------------------------------- /figures/fcolorbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/fcolorbox.png -------------------------------------------------------------------------------- /figures/geometry-option-one.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/geometry-option-one.png -------------------------------------------------------------------------------- /figures/geometry-option-two.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/geometry-option-two.png -------------------------------------------------------------------------------- /figures/glue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/glue.png -------------------------------------------------------------------------------- /figures/ju-li-shi-jian-qu-xian-tu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/ju-li-shi-jian-qu-xian-tu.png -------------------------------------------------------------------------------- /figures/line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/line.png -------------------------------------------------------------------------------- /figures/multicolumn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/multicolumn.png -------------------------------------------------------------------------------- /figures/multicolumn_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/multicolumn_2.png -------------------------------------------------------------------------------- /figures/notecard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/notecard.png -------------------------------------------------------------------------------- /figures/scale_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/scale_table.png -------------------------------------------------------------------------------- /figures/self_define_command_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/self_define_command_1.png -------------------------------------------------------------------------------- /figures/siunitx_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/siunitx_1.png -------------------------------------------------------------------------------- /figures/siunitx_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/siunitx_2.png -------------------------------------------------------------------------------- /figures/siunitx_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/siunitx_3.png -------------------------------------------------------------------------------- /figures/siunitx_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/siunitx_4.png -------------------------------------------------------------------------------- /figures/tcolorbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/tcolorbox.png -------------------------------------------------------------------------------- /figures/temp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/temp.jpg -------------------------------------------------------------------------------- /figures/ubuntu_font_show.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/ubuntu_font_show.png -------------------------------------------------------------------------------- /figures/ubuntu_logo_font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/ubuntu_logo_font.png -------------------------------------------------------------------------------- /figures/vbox_show.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/vbox_show.png -------------------------------------------------------------------------------- /figures/wendu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/wendu.png -------------------------------------------------------------------------------- /figures/xcolor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/xcolor.png -------------------------------------------------------------------------------- /figures/xcolor_mix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/figures/xcolor_mix.png -------------------------------------------------------------------------------- /main.tex: -------------------------------------------------------------------------------- 1 | % !Mode:: "TeX:UTF-8"%確保文檔utf-8編碼 2 | 3 | \documentclass[12pt,oneside]{book} 4 | 5 | \usepackage[minted]{mybook} 6 | \usepackage{mybookcover} 7 | 8 | 9 | \usepackage{longtable} 10 | %si unit 11 | \usepackage{siunitx} 12 | % 文本的单位表示 13 | \sisetup{mode=text} 14 | %num命令两边加上空格 numb 15 | \providecommand{\numb}[1]{{~\num{#1}~}} 16 | \providecommand{\abs}[1]{\lvert#1\rvert} 17 | \providecommand{\ddt}[2]{\frac{d#1}{d#2}} 18 | 19 | 20 | %=========重新定义 quote=====% 21 | \renewenvironment{quote}[1][anonymous] 22 | {\def\quoteauthor{#1} 23 | \list{}{\rightmargin\leftmargin %右间距等于左间距 24 | \itemindent 2em 25 | }\item\relax 26 | \ttfamily} 27 | {\\ 28 | \makebox[\linewidth][r]{\sffamily —\quoteauthor} 29 | \endlist} 30 | 31 | 32 | %重新定义quotation 33 | \renewenvironment{quotation} 34 | {\list{}{\rightmargin\leftmargin %右间距等于左间距 35 | \itemindent 2em%item的缩进也就是第一段的缩进 36 | \listparindent \itemindent %第二段的缩进 37 | }% 38 | \item\relax 39 | \ttfamily} 40 | {\endlist} 41 | 42 | 43 | \newenvironment{shici}{ 44 | \begin{verse} 45 | \centering\large\hspace{12pt}} 46 | {\end{verse}} 47 | 48 | 49 | \title{XeLaTeX指南} 50 | \author{Wander} 51 | \hypersetup{ 52 | pdftitle={XeLaTeX指南}, 53 | pdfauthor={Wander}, 54 | pdfcreator={Wander}, 55 | pdfsubject={计算机.文档开发}, 56 | } 57 | 58 | \begin{document} 59 | \makemytitle 60 | 61 | \flypage{感谢上帝} 62 | 63 | \frontmatter 64 | \addchtoc{序言} 65 | \chapter*{序言} 66 | 我试图收集整理各方面来的xelatex相关的信息,包括自己的实践经验总结,作为后学者的指南手册。 67 | 68 | 一切在尊重版权的基础上出于爱好兴趣和相信自由分享的价值原则上进行。 69 | 70 | 全书主要分为四大块: 71 | \begin{description} 72 | \item[xelatex基础] 这部分内容会就xelatex或者latex的基础知识内容做全面的整理归类排版,争取做到言简意赅并面面俱到和实用性很强的手册性质。 73 | 74 | \item[xelatex进阶] 更深入地讨论xelatex的特有的排版问题。 75 | 76 | \item[tex高级篇] 这部分讨论了tex底层的一些知识。 77 | 78 | \item[附录] 里面有些内容你可能会很感兴趣。 79 | \end{description} 80 | 81 | 82 | 本文的github地址是:\href{https://github.com/a358003542/xelatex-guide-book}{github.com/a358003542/xelatex-guide-book} 83 | 84 | 85 | 86 | \addchtoc{目录} 87 | \setcounter{tocdepth}{2} 88 | \tableofcontents 89 | 90 | 91 | \mainmatter 92 | \part{xelatex基础} 93 | \chapter{背景知识} 94 | \section{TeX} 95 | 以下完全按照wikibook中的latex翻译的。\href{http://en.wikibooks.org/wiki/LaTeX/Introduction}{wikibook-latex} 96 | 97 | Tex是一个底层的标记式的编程语言,Donald Knuth发明的排版系统,可以用来排版出很漂亮的文章。当初Knuth看到自己的文章和书籍被排版的丑陋不堪,于是在1977年开发了这个排版引擎,这个引擎深深地改变了出版业,大力扩展了数字打印设备的潜能。1989年Tex支持了8位字符,然后Tex的开发就被冻结了,只限bug的修复。Tex作为一种编程语言,是支持if-else结构的:你能够在里面执行数学运算(他们在编译文件的时候被执行),等等。不过你会发现要做其他的还是很困难的除了排版文字。Tex对于文章的结构和格式提供了良好的解决方案,使得它成为一个强大的神器。Tex是出了名的稳定,可以运行在各种计算机上,几乎没有bug。Tex的版本是按照$\pi$的序列扩展的,目前到了3.1415926。 98 | 99 | \section{关于Knuth教授} 100 | Knuth教授是\TeX 排版系统的发明人,出于内容精简的目的,关于Knuth教授的生平信息删去了,有兴趣的请参看\href{http://zh.wikipedia.org/wiki/%E9%AB%98%E5%BE%B7%E7%BA%B3}{wiki-高德纳}。 101 | 102 | \section{LaTeX} 103 | LaTeX是一个宏包,其目的是使作者能够利用一个预先定义好的专业页面设置,从而得以高质量地排版和打印他们的作品。LaTeX 最早是由Leslie Lamport编写的,并使用\TeX 作为其排版系统引擎\cite{lshort}。 104 | 105 | \section{XeLaTeX} 106 | 关于XeLaTeX第一是文档是UTF-8编码的,第二是它对各种字体多语言输出文章的解决方案是最完美的,第三是LaTeX里面能够用的命令它一般都能用,第四是编译生成pdf文件使用的命令是xelatex什么什么tex文件,第五是需要知道它内置引擎现在一般是xdvipdfmx。 107 | 108 | 109 | \chapter{beginning} 110 | 在\LaTeX 的代码中最重要的是理解各种各样的命令的功能,正是这些各种各样的命令让你输入的文字显得与众不同。比如说我现在在打很长的一段文字,\LaTeX 会自动换行的,而我在这里按下Enter键 111 | ,实际上并没有换行的效果。理解这一点很重要,\LaTeX 不同于微软的word软件或者其他openoffice之类,不是采用的所见即所得模式,我在这里打的是奇奇怪怪的东西,但是最后显示出来的却可能是很美观的东西。\LaTeX 的一个设计理念就是所想即所得,它甚至有点偏执地要求你组织好你自己的文章的结构,而这正是\LaTeX 的爱好者所推崇的。 112 | 113 | 同样在代码中你空 一个格或者空 很多个格都是没有区别的,都是一个空格\footnote{现在中文之间的空格不会显示了,不清楚是xelatex还是xecjk宏包处理的,这样挺好的。然后如果用pandoc输出epub那里还是会保留一个空格。}。 114 | 115 | 116 | 117 | 在\LaTeX 中空一行和空很多行的效果是一样的,都是空一行,表示另起一段。 118 | 119 | \LaTeX 的命令用到了一些特殊的符号,所以你就不能按照常规用到它们了,这些符号如下: 120 | \begin{Verbatim} 121 | # $ % ^ _ & { } ~ \ 122 | \end{Verbatim} 123 | %$ 124 | 125 | 更详细的说明请参见后面的特殊符号一章\ref{sec:symbols} 。 126 | 127 | \LaTeX 的命令是case~sensitive的。也就是命令是区分大小写的。 128 | 129 | 现在我把最基本的代码说明一下,\LaTeX 的代码的通用格式是这样的,\textbackslash{}开头,然后跟上命令符号,然后跟上[],方括号中放的是该命令的可选参数,然后跟上\{\},花括号里面跟的是该命令的必填参数。具体如下: 130 | \begin{Verbatim} 131 | \command[optional parameters]{parameters} 132 | \end{Verbatim} 133 | 134 | 135 | 比如说本文档的第一行:\verb+\documentclass[12pt,oneside]{book}+ ,意思是描述文章模板的类型为book,也就是一本书,除此之外还有article,report,slides类型等,更详细的讨论参见documentclass说明一章\ref{sec:documentclass} 。 136 | 137 | 然后我们看到第二行代码:\verb+\usepackage{什么宏包}+ ,这个usepackage命令后面跟上你想加载的库文件,等你使用\LaTeX 久了,就会接触到更多的宏包的。 138 | 139 | 然后后面重要的代码有: 140 | \begin{Verbatim} 141 | \begin{document} 142 | 143 | 文章内容 144 | 145 | \end{document} 146 | \end{Verbatim} 147 | 148 | 149 | 其描述了文档的开始和文档的结束。在文档结束命令之后,你写的任何东西都会被\LaTeX 忽略掉。文档环境里面就写着你的文章的内容。 150 | 151 | \section{查看宏包帮助文档} 152 | 这个我先讲了,实际上沉下心来阅读文档是最好的学习\LaTeX 的方法了。比如我要查看xeCJK文档,就在终端中输入: 153 | 154 | \begin{Verbatim} 155 | texdoc xeCJK 156 | \end{Verbatim} 157 | 158 | 159 | 在texmaker的帮助菜单下面有个功能类似的小插件。 160 | 161 | \section{从documentclass说起} 162 | \label{sec:documentclass} 163 | 文档刚开始是preamble区域,放着文档的一些配置,从 \\ 164 | \verb+begin{document}+开始进入正文区,出了 \verb+end{document}+这句话之后后面写的什么程序都不管了。document是一个环境,后面我们会接触很多的环境的。 165 | 166 | documentclass命令的必选参量有article,report,book, slides,beamer等,一般了解这几个就够用了。他们之间有很多细微的差别,这个后面慢慢了解。 167 | 168 | tex有以下文档的分节命令: 169 | 170 | \begin{itemize} 171 | \item part 172 | \item chapter 173 | \item section 174 | \item subsection 175 | \item subsubsection 176 | \item paragraph 177 | \item subparagraph 178 | \end{itemize} 179 | 180 | 181 | 上面的分节命令如果带上星号,如\verb+\chapter*{}+和 \verb+\section*{}+ 这样的形式则表示该分节不进入目录,也不编号。【在某些情况下你可能需要该章节不编号但是也要在目录上显示,请参看\ref{sec:前言加入目录} 的讨论。但更精细的测试显示\verb+\part*+是会进入目录的。】 182 | 183 | 一般paragraph和subparagraph分节不怎么使用,就在文档中一行一行空出来即可。还有subsubsection这个分节也不常使用,因为section之下有subsection已经很好地满足了思想的分级结构。paragraph命令可以构建出类似description环境的效果,不同的是后面不缩进,装载内容容量更大。 184 | 185 | 对于一本书而言目录是很重要的一环,如果一本书的目录结构是乱七八糟的那么这本书不值一看。 186 | 187 | \subsection{一般的可选项} 188 | \begin{itemize} 189 | \item 10pt,11pt,12pt 设置文档所使用字体的大小,默认是10pt。\\ 190 | \cite{wikibook-latex} 191 | \item a4paper ,letterpaper... 定义纸张的大小,此外还有 a5paper等。 192 | \item fleqn 设置该选项将使数学公式左对齐,而不是中间对齐。 193 | \item leqno 设置该选项将使数学公式的编号放置于左侧而不是右侧。 194 | \item titlepage, notitlepage 指定是否在文档标题后开始新一页,article文档类不开始新页,report和book开始。 195 | \item onecolumn, twocolumn 指定LaTeX以单栏或双栏方式排版文档。 196 | \item twoside, oneside 指定LaTeX排版文档为双面或单面格式,article和report默认为单面,book默认为双面。 197 | \item openright, openany 定义chapter开始时仅在奇数页或者随意,book类默认openright,report默认openany,article没有chapter。 198 | 199 | \end{itemize} 200 | 201 | 202 | 203 | \section{书籍的通用结构} 204 | 通常一本书是由好几部份构成的,包括封面、扉页、书名页、目次、序、内文、补充或参考资料、版权页。 205 | 206 | 出版的书籍的封面和扉页这里我们不考虑。电子书籍就从书名页开始说起。也就是我们的maketitle命令。这个时候也可以认为书名页作为了通常意义上的封面。maketitle可以生成多页,你可以考虑把版权页也算在里面,因为出版的书籍那个版权页刚好在背面,而电子书籍我觉得版权页还是放到最后面合适一些,当然多页封面你还可以自己加点名言警句页,这个看自己喜好了。 207 | 208 | 然后接下来是序言部分,自序或者他序都可以。自己编的电子书籍就是自序了,自序内容不宜过长,相当于论文的摘要部分,用最简短的话让别人对这本书有一个大概的印象。 209 | 210 | 接下来如果有listoftables和listoffigures的就放到这里,这个看个人喜好,似乎现在一般都喜欢放在书后面吧。 211 | 212 | 然后是tableofcontents,目录。 213 | 214 | 然后是正文部分,包括引言,前言等。 215 | 216 | 然后是appendix,附录部分是用来提示一些与内容有关而不便载于正文里的资料。 217 | 218 | 然后是索引:是针对这本书中重要资料如人名、地名、概念等的查检。将本文的重要概念列出,并注明出现在文中的页次。它是依一定的方法排列,通常中文是按字体的笔划多寡决先后顺序,西文则按字母的顺序排列,以便检查。 通常附录是直接资料,索引则是提供查询资料的线索。(索引主要是方便纸质书检索,我觉得如果一本书如果电子化了还是很容易搜索了,可以不加索引了。) 219 | 220 | 221 | \section{页码控制} 222 | \label{sec:页码} 223 | frontmatter命令跟在begin document后面,接下来页码为罗马数字。更确切来说应该在封面和扉页的后面,虽然封面设计会默认不显示页眉页脚这些,但放在封面和扉页后面会更合适些。 224 | 225 | mainmatter命令放在正文开始的前面,表示页码为阿拉伯数字开始计数。【书籍从序言到目录完结应该是罗马数字,当要引用一本书的内容时候,一般是书名然后P123,这个123就是123页的意思。所以作者请不要在序言部分长篇大论,最多就是关于本书内容的简要介绍和一些感谢之类的,因为假如你的序言部分有什么重要的信息别人要引用,会让别人有点不太好办。mainmatter之后如果有什么一般性的讨论,前言,绪论,引言都是可以的。】 226 | 227 | appendix命令表示附录开始,后面各章节改为字母标记。页码没有变化 228 | 229 | backmatter命令放在参考文献或者索引的前面。章节编号关掉,页码没有变化。\footnote{backmatter不能在appendix前面,请参考\href{http://tex.stackexchange.com/questions/20538/what-is-the-right-order-when-using-frontmatter-tableofcontents-mainmatter}{这个网站}。} 230 | 231 | 232 | 233 | \chapter{页面布局} 234 | 页面布局最好用\emph{geometry}宏包调节。 235 | 236 | \section{geometry宏包详细讨论} 237 | 页面布局尺寸由geometry宏包指定,页面布局包含很多参量也就是geometry的可选项,请看下图\ref{fig:geometry-option-one}: 238 | 239 | \begin{figure}[H] 240 | \centering 241 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{geometry-option-one.png} 242 | \caption{geometry选项1} 243 | \label{fig:geometry-option-one} 244 | \end{figure} 245 | 246 | 247 | geometry提供的纸张类型很多,从a0paper一直到a6paper都有,还有b1paper到b6paper系列等等。纸张类型指定了后面的paperwidth和paperheight就都确定了。 248 | 249 | 我们先来看横向参量,paperwidth是纸张的宽度,textwidth是正文宽度,marginparsep指旁注和正文之间的间距,marginparwidth指旁注宽度,left指左边空白宽度,right指右边空白宽度。如果book类型是twoside的,那么left最好命名为inner,也就是类似出版书籍靠里面的那段空白宽度,类似的right最好命名为outer,靠外面的那段空白宽度。其中默认情况下width=textwidth,如果加入选项\\includemp=true,那么:\\width=textwidth+marginparsep+marginparwidth。然后还有:\\paperwidth=left+width+right。 250 | \footnote{主要是针对有旁注的情况,在设置为true之后,那么旁注宽度你定义是多少就是多少,左边距右边距是多少就是多少,然后剩下的正文宽度是一个从量(即自动确定的量)了。} 251 | 252 | 再来看竖向参量,paperheight为纸张高度,textheight是正文高度,top为上面的空白高度,bottom为下面的高度,默认top包含页眉高度headheight和页眉于正文间的一段小空白headsep,bottom包含页脚高度\footnote{这里的概念理清一下,headheight是页眉高度,保证页眉内容能够装的下即可,而headsep是页眉(一般页眉靠下)和正文间的空白距离,也就是你看到的页眉上面的那段空白有top减去headsep再减去headheight剩下的距离,然后这段空白从视觉上来说还有你的页眉文本上面没有填充的部分。而footnote命令插入的文本和页码之间的空白间距是由footskip控制的,然后bottom减去footskip还会得到一个值,这个值是页码下面的空白距离。}footskip和下面的一段空白。所以你的top至少要大于headheight高度。然后中间的区域高度为height。默认情况下height=textheight,请看下图\ref{fig:geometry-option-two} 253 | 254 | \begin{figure}[H] 255 | \centering 256 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{geometry-option-two.png} 257 | \caption{geometry选项2} 258 | \label{fig:geometry-option-two} 259 | \end{figure} 260 | 261 | 如果加上includehead=true选项,那么就和上图右边描述的类似,页眉部分计入height,类似的有includefoot=true,那么页脚部分也计入height。 262 | 263 | geometry的机制是以上讨论的横向或者竖向参量指定足够的数量之后,剩下的可以自动计算得到。没有明确指定的参量虽然可以通过计算得到,但是在后面似乎是不能够作为变量使用的? 264 | 265 | 266 | 267 | 268 | \chapter{字体} 269 | 我们知道xelatex的机制可以调用系统内的任意字体,当然系统没有的字体就要自己安装了(请参看附录ubuntu入门的安装系统字体部分)。 270 | 271 | \section{字体的五种属性} 272 | \LaTeX 的字体有五种属性,这五种属性是:字型编码,字族,字型系列,字形,字号,即:encoding,family,series,shape and size。 273 | 274 | \subsection{字型编码} 275 | 字型编码即各个个别的字在一个字型里头的排列顺序以及安排方式。原始的\TeX 字型编码我们就称为OT1(Old TEX text encoding),这是预设的,如果都不指定字型编码,那所使用的就是OT1编码。在目前新一代的字型编码里头,字的安排方式及内容和OT1不一样,例如T1等。 276 | 277 | 278 | \subsection{字族} 279 | 字族分为三大类,roman or serif(rm),sans serif(sf)和 mono\-space(tt)。\footnote{下面参考了\href{http://wiki.ubuntu-tw.org/index.php?title=HowtoCustomFontswithFontconfig}{这个网站}} 280 | 281 | 282 | \begin{description} 283 | \item[serif] Serif中文译为「有衬线字体」,衬线即是印刷字体在每个笔划起始与终止处,加上短线或三角突起等,以便于快速辨认字符,利于阅读,为印刷专用字体。旧版Windows与较旧的Linux发行版以此为预设显示字体,而英文新版则改为Sans-Serif,中文新版则是:当字体大于某一程度时,则将 Serif的明体或宋体,以Sans的黑体取代。 284 | 285 | Serif字体著名的有:Times New Roman、DejaVu Serif、宋体、明体等。 286 | 287 | \item[sans-serif] Sans-Serif中文译为「无衬线字体」,专用于荧幕、简报、艺术字体、展示等,较美观,但不适于长时间阅读。多数英文语系的作业系统多以此为预设字体,而采用此种字体为预设的中文作业系统,以Mac系统最为著名。 288 | 289 | Sans-Serif 字体著名的有:DejaVu Sans、Helvetica、Verdana、圆体、黑体等。 290 | 291 | \item[monospace] Mono意思是「单一的」,space 意思是「空间」,中文翻为「等宽字体」。等宽字是打字机时代下的遗产,每个英文字母皆设计为同一宽度,以便于排版;现代为节省不必要空间的浪费,依字母形状分配其宽度,如m与i其宽度便不相同,不相信可以拿尺来量看看。Monospace 现多用于终端机显示、程序码表示等。 292 | 293 | Monospace字体著名的有:Andale Mono、DejaVu Sans Mono 、 Courier、AR PL New Sung Mono。 294 | \end{description} 295 | 296 | 297 | \subsection{字型系列} 298 | 正常用的是medium,\textbf{m}。粗体是bold,\textbf{b}。然后还有Bold extended,\textbf{bx}。还有Semi-bold,\textbf{sb}。和Condensed,\textbf{c} 299 | 300 | 301 | \subsection{字形} 302 | 字形有正常的normal,\textbf{n}。还有意大利斜体Italic,\textbf{it}。斜体Slanted,\textbf{sl}。和Small Caps,\textbf{sc}。 303 | 304 | 305 | \subsection{字号} 306 | 比如说本文设置的就是12pt。 307 | 308 | 309 | 310 | \section{调整五种属性} 311 | \subsection{调整字型编码} 312 | XeLaTeX 只处理UTF-8编码,那个调整字体编码的inputenc和fontenc宏包都不要用了。 313 | 314 | 315 | \subsection{调整字族} 316 | 有两种方法设置,一种是命令式的,一种是环境式的。roman font family是默认的字族,一般不需要明确设置。 317 | 318 | \begin{table}[H] 319 | \centering 320 | \begin{tabular}{|c|c|c|} 321 | \hline 322 | 命令式 & 环境式 & 描述 \\ 323 | \hline 324 | \verb+ \textrm{text}+ & \verb+ {\rmfamily text}+ & roman字族 \\ 325 | \verb+ \textsf{text}+ & \verb+ {\sffamily text}+ & sans-serif字族 \\ 326 | \verb+ \texttt{text}+ & \verb+ {\ttfamily text}+ & monospace字族 \\ 327 | \hline 328 | \end{tabular} 329 | \caption{调整字族} 330 | \label{tab:调整字族} 331 | \end{table} 332 | 333 | \subsection{调整字型系列} 334 | 默认的medium,一般不需要设置,然后还有一个bold,即字体加粗。 335 | 336 | \begin{table}[H] 337 | \centering 338 | \begin{tabular}{|c|c|c|} 339 | \hline 340 | 命令式 & 环境式 & 描述 \\ 341 | \hline 342 | \verb+ \textmd{text...}+ & \verb+ {\mdseries text...}+ & 正常字体粗细 \\ 343 | \verb+ \textbf{text...}+ & \verb+ {\bfseries text...}+ & bold 粗体 \\ 344 | \hline 345 | \end{tabular} 346 | \caption{调整字型系列} 347 | \label{tab:调整字型系列} 348 | \end{table} 349 | 350 | 351 | \subsection{调整字形} 352 | 默认是upright shape,常用的字形如下: 353 | 354 | \begin{table}[H] 355 | \centering 356 | \begin{tabular}{|c|c|c|} 357 | \hline 358 | 命令式 & 环境式 & 描述 \\ 359 | \hline 360 | \verb+ \textup{text...}+ & \verb+ {\upshape text...}+ & 正常字形 \\ 361 | \verb+ \textit{text...}+ & \verb+ {\itshape text...}+ & 意大利斜体 \\ 362 | \verb+ \textsl{text...}+ & \verb+ {\slshape text...}+ & 斜体 \\ 363 | \verb+ \textsc{text...}+ & \verb+ {\scshape text...}+ & small caps \\ 364 | \hline 365 | \end{tabular} 366 | \caption{调整字形} 367 | \label{tab:调整字形} 368 | \end{table} 369 | 370 | 371 | \subsection{调整字号} 372 | \subsubsection{相对字号调整} 373 | \LaTeX 里面自带的调整相对字号命令如下: 374 | \begin{table}[H] 375 | \centering 376 | \begin{tabular}{|l|l|} 377 | \hline 378 | 命令 & 输出\\ 379 | \hline 380 | \verb+{\tiny test line}+ & {\tiny test line}\\ 381 | \verb+{\scriptsize test line}+ & {\scriptsize test line}\\ 382 | \verb+{\footnotesize test line}+ & {\footnotesize test line}\\ 383 | \verb+{\small test line}+ & {\small test line}\\ 384 | \verb+{\normalsize test line}+ & {\normalsize test line}\\ 385 | \verb+{\large test line}+ & {\large test line}\\ 386 | \verb+{\Large test line}+ & {\Large test line}\\ 387 | \verb+{\LARGE test line}+ & {\LARGE test line}\\ 388 | \verb+{\huge test line}+ & {\huge test line}\\ 389 | \verb+{\Huge test line}+ & {\Huge test line}\\ 390 | \hline 391 | \end{tabular} 392 | \caption{调整字体大小命令} 393 | \label{tab:调整字体大小命令} 394 | \end{table} 395 | 396 | 然后我们看下图,不同字号下这些命令确切的大小\footnote{不知道你注意到没有,本文用的是12pt,上面表格上的huge和Huge字号还是有差异,这是因为我加载了moresize宏包的缘故。}: 397 | 398 | \begin{table}[H] 399 | \centering 400 | \begin{tabular}{@{}llll@{}} 401 | \toprule 402 | size & 10pt (default) & 11pt option & 12pt option \\ \midrule 403 | \textbackslash tiny & 5pt & 6pt & 6pt \\ 404 | \textbackslash scriptsize & 7pt & 8pt & 8pt \\ 405 | \textbackslash footnotesize & 8pt & 9pt & 10pt \\ 406 | \textbackslash small & 9pt & 10pt & 11pt \\ 407 | \textbackslash normalsize & 10pt & 11pt & 12pt \\ 408 | \textbackslash large & 12pt & 12pt & 14pt \\ 409 | \textbackslash Large & 14pt & 14pt & 17pt \\ 410 | \textbackslash LARGE & 17pt & 17pt & 20pt \\ 411 | \textbackslash huge & 20pt & 20pt & 25pt \\ 412 | \textbackslash Huge & 25pt & 25pt & 25pt \\ \bottomrule 413 | \end{tabular} 414 | \caption{字体具体大小} 415 | \label{tab:字体具体大小} 416 | \end{table} 417 | 418 | 419 | \subsubsection{绝对字号调整} 420 | 上面的命令基本上够用了,并不鼓励使用绝对字号。不过有的时候还是有用的,比如旁注环境需要同时调整字体大小和行距,使用这个命令注意不要对文本中某一小段文字使用,否则会造成行距的不一致。 421 | 比如这个旁注使用的命令是: 422 | 423 | \begin{Verbatim} 424 | \newcommand{\sidenote}[1]{\marginpar{ 425 | \fontsize{10pt}{20pt}\selectfont #1}} 426 | \end{Verbatim} 427 | 428 | 其中fontsize就是调整字号的命令,第一个参量是字体的大小,第二个参量是行距。然后后面\textbackslash selectfont 必须写上,就理解为表示对后面的字体进行操作吧。类似的还有fontencoding,fontfamily,fontseries,fontshape命令,这些本文略过。 429 | 430 | 431 | \chapter{字体配置} 432 | \section{fontspec宏包详解} 433 | fontspec宏包主要用于英文字体的设置,中文字体的设置建议用xeCJK宏包来管理。\emph{XeLaTeX 只能使用opentype和truetype字体。} 434 | 435 | \subsection{基本的命令} 436 | fontspec宏包最基本的应用就是用setmainfont来设置文档的默认roman字族字体的,setmainfont原来的名字叫setromanfont。\footnote{\href{http://tex.stackexchange.com/questions/70413/problem-with-xetex-latex-and-system-fonts}{参考了这个网站}}setsansfonts是设置文档默认sans-serif字族字体的,setmonofont是设置monospace字族字体的。然后我们看到前面都有一个可选项Mapping=tex-text,这个说是什么让XeTeX 文字分布更好的,可能和正确断行有关系,不大确切。 437 | 438 | fontspec宏包有一个和这个宏包名字一样的命令,这个命令非常的基本,大约相当于引擎的入门口,我估计前面三个命令实际上是建构在fontspec命令之上的。fontspec命令的作用不光临时改变字体。还可以加上很多可选项,比如字体尺寸,颜色等等。总之fontspec命令的优先级要高于前面的三大默认字体设置命令。请看下面的例子: 439 | 440 | \begin{Verbatim} 441 | {\fontspec[Scale=4,Color=magenta]{Ubuntu} this is a test.} 442 | \end{Verbatim} 443 | 444 | 下面显示的是图片,你需要系统安装了ubuntu字体才能运行上面的代码\footnote{ubuntu字体可以在\href{https://design.ubuntu.com/font/}{这里}下载。}。 445 | 446 | \begin{figure}[H] 447 | \centering 448 | \includegraphics[width=0.8\linewidth ,totalheight=0.95\textheight , keepaspectratio]{ubuntu_font_show.png} 449 | \end{figure} 450 | 451 | 452 | 另外还有一个有用的命令就是newfontfamily,这个命令相当于把font\-spec命令包起来再新建一个命令。新建的那些字体命令就像\verb+\sffamily+之类的命令一样使用。比如加上这一行命令之后: 453 | 454 | \begin{Verbatim} 455 | \newfontfamily{\ubuntu}[Scale=3]{Ubuntu} 456 | \end{Verbatim} 457 | 458 | 后面就可以使用 \verb+\ubuntu{这个命令了}+ 。 459 | 460 | 以上基本命令总结如下: 461 | \begin{Verbatim} 462 | \fontspec [ font features ] { font name } 463 | \setmainfont [ font features ] { font name } 464 | \setsansfont [ font features ] { font name } 465 | \setmonofont [ font features ] { font name } 466 | \newfontfamily{ cmd }[ font features ] { font name } 467 | \end{Verbatim} 468 | 469 | 上面的font name在安装字体的时候说明清楚了,比如说用fc-list命令调出来的\textit{宋体,SimSun:style=Regular}中字体名字就是宋体或者SimSun。而在font-manager里面比如第一行显示\textit{Comic Sans MS Regular},字体名就是Comic Sans Ms。接下来主要讨论font features的内容,所讨论的内容以上几个基本命令都适用。由于xeCJK的fontfeatures可选项是继承自fontspec,所以下面的讨论也适用于xeCJK宏包。 470 | 471 | \subsection{font features的讨论} 472 | 一个字体的字族之下还分为不同的字形,默认的字形设置可能并不能满足你的要求。有一些字体甚至没有粗体或者意大利体这样的字形。一般的玩家就选用默认字形设置足有了,最多在mainfont哪里设置下boldfont和italicfont。比如类似下面这样配置: 473 | 474 | \begin{Verbatim} 475 | \setCJKmainfont[BoldFont=Adobe 黑体 Std, ItalicFont=Adobe 楷体 Std]{Adobe 宋体 Std} 476 | \end{Verbatim} 477 | 478 | 具体字形有: 479 | 480 | \begin{Verbatim} 481 | BoldFont = font name 482 | ItalicFont = font name 483 | BoldItalicFont = font name 484 | SlantedFont = font name 485 | BoldSlantedFont = font name 486 | SmallCapsFont = font name 487 | \end{Verbatim} 488 | 489 | 490 | \subsection{Color} 491 | 前面的例子我们看到了Color属性的定制,在这里推荐适用xcolor宏包。XeLaTeX 默认使用的是xdvipdfm,不支持透明颜色。然后xcolor宏包对于颜色的讨论请参看颜色一节\ref{sec:颜色} 492 | 493 | \subsection{字体大小} 494 | 在前面的那个例子也用到了Scale选项,选个数字来整体调整这个字体的尺寸大小。还有两个常量值,一个是MatchLowercase,一个是MatchUppercase。就是变成小写字母一样的或者大写字母一样的大小。 495 | 496 | \subsection{词间距——WordSpace} 497 | 觉得默认的设置更有弹性吧,一般的玩家没必要动它。 498 | 499 | \subsection{标点后间距——PunctuationSpace} 500 | 从零开始可以加点距离。 501 | 502 | \subsection{断字符号——HyphenChar} 503 | 就是要换行了选择从哪里断字的符号,比如设置HyphenChar={+},那么标明+,就从哪里断字。默认的是\textbackslash{}- 。 504 | 505 | \subsection{字母之间的距离——LetterSpace} 506 | 从零开始加点距离,而且只适用于小写字母,感觉很累赘。而且这个feature\emph{只适用于XeTeX} 。 507 | 508 | 509 | \subsection{最后两个命令} 510 | 最后还有两个命令defaultfontfeatures和addfontfeatures。有什么优先级:\\ addfontfeatures>fontspec>defaultfontfeatures。觉得太花哨了暂时应该用不到。 511 | 512 | 513 | 514 | 515 | \section{设置数学字体} 516 | 觉得默认的数学字体也很好看的,就不折腾了。 517 | 518 | 这里简单提一下,数学没有太多额外需要加载的宏包,其中amssymb和amsmath这两个宏包必备,基本上大家都加载了的。 519 | 520 | 然后通过\verb+\everymath{\displaystyle}+这个语句可以让文本内的数学形式,比如分数显得更大更好看一点。其他问题这里都略过了。 521 | 522 | \begin{Verbatim} 523 | \RequirePackage{amssymb,amsmath} 524 | \everymath{\displaystyle} 525 | \end{Verbatim} 526 | 527 | 528 | 529 | \section{xeCJK宏包详解} 530 | xeCJK宏包只处理CJK字符在这里指中文字,也就是英文字还是用前面的fontspec宏包来处理。 531 | 532 | \subsection{xeCJK宏包的一些命令} 533 | 现在对照fontspec宏包对xeCJK新建的只针对CJK字符处理的命令说明如下,其中各个命令的用法和fontfeatures都是类似的。 534 | \begin{description} 535 | \item[setCJKmainfont] 类似于setmainfont。 536 | \item[setCJKsansfont] 类似于setsansfont。 537 | \item[setCJKmonofont] 类似于setmonofont。 538 | \item[CJKfontspec] 类似于fontspec。 539 | \item[newCJKfontfamily] 类似于newfontfamily。 540 | \item[defaultCJKfontfeatures] 类似于defaultfontfeatures。 541 | \item[addCJKfontfeatures] 类似于addfontfeatures。 542 | \item[setCJKmathfont] 估计应该类似于setmathrm。 543 | \end{description} 544 | 545 | \subsection{设置CJK字符大小} 546 | 可以通过如下命令: 547 | \begin{Verbatim} 548 | \defaultCJKfontfeatures{Scale=1.2} 549 | \end{Verbatim} 550 | 来调整所有CJK字体的属性,比如上面代码的意思就是所有CJK字体都放大1.2倍。比如你在documentclass里面设置10pt,那么实际CJK字符是12pt。\footnote{以前我喜欢放大CJK字体,但是后来发现这样放大之后让数学环境下的字体显得太小很不好看,而且这样整了之后似乎数学环境下的字体也不能通过DeclareMathSizes命令调节了。} 551 | 552 | 553 | \section{UTF-8编码} 554 | texmaker软件并没有这个问题,不管怎么样,加上这样一行代码没什么害处喽。确保文档以utf-8编码打开和保存。具体就是在文档开头加上如下代码: 555 | 556 | \begin{Verbatim} 557 | % !Mode:: "TeX:UTF-8" 558 | \end{Verbatim} 559 | 560 | 本文只关注于UTF-8编码。 561 | 562 | 563 | \chapter{特殊的符号} 564 | \label{sec:symbols} 565 | \section{去掉符号命令后面的空格} 566 | 值得一提的是命令如果后面跟上一个花括号,后面的字符紧跟花括号,那么命令显示的符号和后面的字符就没有空格了。比如这里\& a之间就有一个空格,加上花括号\verb+\&{}a+,\&{}a就没有了。 567 | 568 | \section{基本的特殊符号} 569 | \subsection{\textbackslash} 570 | \textbackslash ,我们知道命令的开头表示就用它,所以在文档中是不能直接使用的,如果需要显示\textbackslash ,需要输入\textbackslash textbackslash来显示。 571 | 572 | \subsection{\{和\}} 573 | \{和\},同上,作为命令的格式。如要显示前面加上\textbackslash 符号。 574 | 575 | \subsection{\%} 576 | \% ,我们知道这个符号在文档是用来标记注释信息的开始的,所以在文档也不能直接使用。在前面加个\textbackslash 即可。 577 | 578 | \subsection{\~{}} 579 | \~ ,这个符号在文档中产生一格空白,如要显示在前面加上\textbackslash 符号。这样显示的波浪号有点小。还可以进入数学模式下输入\textbackslash sim,在texmaker左边的关系符号一栏中也可以找到。所以为了美观的话就用数学模式吧。然后在Rime输入法里面我们看到还有一种符号是全角下的波浪号~。我比较了下这个和前面两个都不相同,简单起见用这个全角的波浪号也是可以的。——这里所谓的Rime输入法意思就是中文输入法下的全角输入。 580 | 581 | \subsection{\$} 582 | \$ ,美元符号之所以不可以用是因为它标记了数学模式的开始和结束。比如说我要输入字母$\pi$,就是在两个美元符号中间输入\textbackslash pi即可。如果直接从输入法输入希腊字母的符号π,这个也是可以正常显示的,只是没有前面数学模式下的美观。我查了一下,数学模式下的那个$\pi$也是unicode区域里面的那个希腊字母,我想只是字体问题了。\footnote{\href{http://www.johndcook.com/unicode_latex.html}{这个网站}用来查找unicode和\LaTeX 命令的对应关系} 583 | 584 | \subsection{\#} 585 | \# ,这个符号没怎么接触,latex123说是定义巨集的,前面加上\textbackslash 即可。 586 | 587 | \subsection{\^{}和\_{}} 588 | \^{}和\_{},这两个符号表示进入数学模式之后进入上标和进入下标。这两个符号在文本中后面还要跟一对花括号,否则显示会出问题。 589 | 590 | \subsection{\&} 591 | \& ,这个符号表示表格中的分隔符。要显示前面加上\textbackslash 即可。 592 | 593 | \subsection{单引号和双引号} 594 | 你可以用\textbackslash textquotedblleft来表示左双引号,用:\textbackslash textquotedblright 来表示右双引号。用\textbackslash textquoteleft来表示左单引号,用\textbackslash textquoteright来表示右单引号。 595 | 596 | 然后还有敲键盘的方法,要左边和右边区别对待,比如说左单引号就是点击ESC下面那个键,右单引号是点击分号右边那个键;而左双引号是点两次ESC下面那个键,右双引号是按住shift,然后点击分号右边那个键。 597 | 598 | 一边单引号和双引号都用全角模式,中文的输入法调试好会很方便输入的,这不存在什么问题。至于英文左单引号和右单引号好像一般不怎么区分。 599 | 600 | \subsection{破折号和连字号} 601 | 连字号就是一个这个[-] ,可以直接在键盘上输入。\\ 602 | 短破折号就是两个-连续输入成为→ [--]\\ 603 | 长破折号就是三个-连续输入成为→ [---]\\ 604 | 负号如果在数学模式下是→ $ -1 $ 如果有时嫌麻烦就直接-1应该可以接受把。 605 | 606 | 此外中文全角短的连字号有[-],unicode码是U+FF0D;长破折号是[——],有两个unicode码U+2014的符号组成。值得注意的是长破折号的一个,[—],和前面的全角短连字号也是有所不同的,似乎稍微长一点,一般不怎么用吧,但我发现有些书排版有时用到这个符号。 607 | 608 | \subsubsection{两个连字号的显示} 609 | 比如要显示终端选项的时候有两个短连字号,如果你直接输入两个--就变成短破折号了。如果你要有这样的显示效果,-{}-,那么你需要中间加一个花括号\footnote{\href{http://tex.stackexchange.com/questions/9813/how-can-i-stop-latex-from-converting-two-hyphens-to-a-single-hyphen-when-loading}{参考网站}}。下面是三个连字号的例子:\\ 610 | \verb+-{}-{}-+\\ 611 | -{}-{}- 612 | 613 | 614 | \subsection{温度的度} 615 | 在texmaker左边的关系负号哪里我们可以看到一个小圆圈,输入命令是\textbackslash circ,当然需要在数学模式下。现在就需要让这个小圆圈位于上标即可。前面的符号介绍我们提及\^{},就是进入上标显示,上标的内容在\^{}后面的那个花括号内,于是我们就知道三十度怎么画了。$ 30^{\circ} $ ,注意texmaker左边有快捷键。点起来很方便的。具体代码是:\$ 30\^{}\{\textbackslash circ\} \$。当然你可以直接用rime输入法打出这个温度的度:°,℃。在输出\%候选项哪里。 616 | 617 | \subsubsection{更加专业的做法:} 618 | 输入温度的度的更加专业的做法利用siunitx宏包的degreeCelsius命令输出:\verb+30\si{\degreeCelsius} and 45\si{\degree}+ 619 | 620 | \begin{figure}[H] 621 | \centering 622 | \includegraphics[scale=1 , keepaspectratio]{wendu.png} 623 | \end{figure} 624 | 625 | \subsection{省略号} 626 | 英文输入法下直接输入三个小数点和使用 \verb+\ldots+ 命令区别不大,中文省略号请使用中文输入法下的全角模式下的省略号,一般输入法快捷键是 \verb|Shift+6|。 627 | 628 | 629 | 630 | \chapter{初步中文化} 631 | 主要是些原\LaTeX 常量是英文单词,然后改成中文字即可。看看代码就清楚了。 632 | \begin{Verbatim} 633 | \renewcommand\contentsname{目~录} 634 | \newcommand\econtentsname{Contents} 635 | \renewcommand\listfigurename{插图目录} 636 | \renewcommand\listtablename{表格目录} 637 | \renewcommand\bibname{参~考~资~料} 638 | \renewcommand\indexname{索~引} 639 | \renewcommand\figurename{图} 640 | \renewcommand\tablename{表} 641 | \renewcommand\partname{部分} 642 | \renewcommand\appendixname{附录} 643 | \renewcommand{\abstractname}{摘~要} 644 | \renewcommand{\today}{\number\year{}年\number\month{}月\number\day{}日} 645 | \end{Verbatim} 646 | 647 | 值得一提的是不同的文档类包含不同的命令,比如有的文档类可能没有定义today这个命令,比如article类不包含参考文献命令等。 648 | 649 | 650 | 651 | \chapter{段落} 652 | \section{换行和分段} 653 | 一个意思写一个段落,意思没说完就不要分段,在文章中一个段落的书写就是直接写就是了,\LaTeX 会自动处理好一切的。简单的分段的做法就是空一行。这样分段首行缩进仍然存在,表示不同的段落。 654 | 655 | 如果你只是想换行而不分段,那么用命令 \verb+\\+ 可以满足你的要求。 656 | 657 | \textbackslash \textbackslash 命令还有一个用法,比如后面跟上[10pt],表示在原有行距的基础上再加上额外的空白距离,参数也可以是负数。 658 | 659 | 换行不空一行在tex文档中的效果只是加上一个空格,你可以前面那行后面加上\%{}来取消这个空格。 660 | 661 | 662 | \section{断字} 663 | 如果你编译的时候出现了overfull hbox什么的错误,一般是断字出现问题了,有字越过文档边界了。命令\textbackslash \textbackslash 是强制换行。还有一个换行命令\textbackslash linebreak,这个命令后面还可以跟个可选项,但意义我不大明确。一般就是观察生成的文档,然后选择合适的位置插入linebreak命令。这个断行命令断行之后,前面那行的文字将会扩展充满整行,在越界小距离的情况下还是可行的,但是距离大了这一行扩展导致字间距过大也不是十分美观。 664 | 665 | 一般断字问题主要是英文单词的断字,你可以在你想要断字的位置加上\verb+\- +,这样系统会自动判断,如果这里适合断字它就会在这里断字,这种断字方法不会加上符号\verb+-+。其实还有一种直接的断字方法,那就是在你想要断字的文字加上\verb+-\\+,这样会显示符号\verb+-+。第三种断字方法就是在你觉得可能要断字的地方加上符号\verb+-+,这样系统会自动判断在那里断字,然后也会显示符号\verb+-+。 666 | 667 | 668 | 669 | \section[段落中的行距]{段落中的行距\footnote{参考了\href{http://www.complang.tuwien.ac.at/anton/latex/baselineskip.html}{这个网站}}} 670 | \label{sec:段落中的行距} 671 | 672 | \begin{Verbatim} 673 | \setlength{\baselineskip}{22pt} 674 | \end{Verbatim} 675 | 676 | 上面的代码就是设置行间距的。一行一行之间的间距也是一个glue,我们知道glue有基本的space和伸缩量。行距的基本space由命令baselineskip控制,伸缩量有baselinestretch命令。\footnote{实际上这个多少有点揣测的意思。} 677 | 678 | 段落行间距的缩放可以使用\verb+linespread+命令,在刚开始的配置内容里写上即可,不需要额外的宏包加载。其中\verb+\linespread{1.3}+的效果相当于setspace宏包里面的onehalfspacing,如果是1.6则相当于doublespacing,然后当然,1.4,1.5等等都随你设置了。 679 | 680 | 值得注意的是linespread命令还会对表格有拉伸效果,表格行间距是\verb+\arraystretch+这个命令来控制的。 681 | 682 | 可以在导言区如下全局控制表格行间距的缩放: 683 | 684 | \begin{Verbatim} 685 | \renewcommand{\arraystretch}{1.5} 686 | \end{Verbatim} 687 | 688 | 如果只想控制某个表格行间距的缩放,可以用 \verb+{ ... }+ 花括号封装出一个临时的作用域环境。 689 | 690 | 691 | \subsection{baselineskip} 692 | 段落中行之间上下间距\footnote{一行一行就是横向的盒子,行间距就是横向的盒子之间的上下间距。}由三个命令控制:baselineskip,lineskip和lineskiplimit。简单的说明就是首先间距是baselineskip,但是如果上面的盒子伸的太下或者下面的盒子伸的太高,那么他们就可能会碰到一起。lineskiplimit控制的就是盒子之间最小间距,比如0pt。当baselineskip减去上面的盒子的深度depth再减去下面盒子的高度height然后得到的值比lineskiplimit小,那么跳转方案就会选择lineskip模式。也就是上面盒子最低的点和下面盒子最高的点之间的距离是lineskip那么多。\footnote{参看了a beginner's book of \TeX 的spacing between boxes一节。} 693 | 694 | 我感觉自己设置一个baselineskip已经很满足要求了,尤其个别字用Huge命令的时候效果也还行。 695 | 696 | 697 | \subsection{baselinestretch} 698 | baselinestretch量相当于行间距glue的伸缩量,也就是对前面的baselineskip做一定的伸缩\footnote{参看的\href{http://tex.stackexchange.com/questions/49596/no-effect-of-baselinestretch}{这个网站}}。这个命令要使用的话格式如下:\\ 699 | \verb+\renewcommand{\baselinestretch}{伸缩量}+\\ 700 | 这个命令等价于:\\ 701 | \verb+\linespread{伸缩量}+\\ 702 | 不过这不是故事的全部。如果要在文档中改变行间距必须采用如下的形式:\\ 703 | \verb+{\linespread{伸缩量}\selectfont sometext \par}+ 704 | 705 | {\linespread{3} \selectfont 其中伸缩量和前面说的一样是:设为1.3就是1.5倍行距,1.6就是双倍行距,其他自由发挥。除了要封闭环境否则对其他文本有影响外,还需要加上selectfont命令,此外最后还必须加上\textbackslash par命令,否则会没有效果。\par} 706 | 707 | 708 | 709 | \section{段落间距} 710 | \verb+\setlength{\parskip}{1.6ex plus 0.2ex minus 0.2ex}+\\ 711 | 段落间距也就是一段和一段之间的空白距离。上面就是本文段落间距的设置代码。parskip是一个length量。其中距离设置设置一个固定量和一个加量还有一个减量,wikibook中说很有用,不太清楚。 712 | 713 | 714 | \section{段首缩进} 715 | \subsection{段首缩进量调整} 716 | \begin{Verbatim} 717 | \setlength{\parindent}{\textpt * \real{2}} 718 | \end{Verbatim} 719 | 720 | 上面代码就是设置段首缩进量的,其中parindent是一个length量。具体就是两个字符的意思。这里预先需要加载calc宏包\footnote{注意乘法乘以小数的时候需要用real命令处理。},为了让设置的距离更加相对化,我新建的一个长度量textpt:\\ 721 | \verb+\newlength{\textpt}+\\ 722 | \verb+\setlength{\textpt}{11pt}+\\ 723 | 本文的默认字体大小值是11pt,然后传递到了textpt这里。 724 | 725 | 726 | \subsection{章节第一段的缩进} 727 | 默认章节第一段是不会缩进的,如果你希望每个章节的第一段也缩进那么就需要加载 \textbf{indentfirst} 宏包即可。如果你希望某一段不缩进就用noindent命令吧。 728 | 729 | 730 | 731 | \section{段落对齐} 732 | \label{sec:段落对齐} 733 | flushleft环境为左对齐环境,flushright环境为右对齐环境,center为居中环境。这些命令还可以控制表格和图片的位置。简单示例如下: 734 | 735 | \begin{Verbatim} 736 | \begin{flushright} 737 | 右边才是王道。 738 | \end{flushright} 739 | \end{Verbatim} 740 | 741 | \begin{flushright} 742 | 右边才是王道。 743 | \end{flushright} 744 | 745 | 746 | \chapter{页眉页脚设计} 747 | 页眉页脚设计推荐用\emph{fancyhdr}宏包。 748 | \section{观察} 749 | 我什么都没设置,生成的文档有章名的那一页中间有页码,其他页右上角有页码。有章名的那一节可能样式是plain,其他页可能是默认的myheadings样式。 750 | 751 | \section{全部信息归零} 752 | \subsection{plain样式重置} 753 | fancyhdr宏包提供了一个命令fancypagestyle来重新或者定义一个新的页眉页脚样式。现在我将plain样式所有信息全部清除,宁愿没有也不愿出现其他别样的信息。 754 | \begin{Verbatim} 755 | \fancypagestyle{plain}{ 756 | \fancyhf{} 757 | \renewcommand{\headrulewidth}{0pt} 758 | \renewcommand{\footrulewidth}{0pt}} 759 | \end{Verbatim} 760 | 该代码第一行是提出要重新定义plain样式,然后里面包含新的定义。第二行是所有的页眉页脚信息换为空值,第三行是将页眉那条线宽度设为0pt,也就是不显示了,第四行类似是页脚那根线不显示了。 761 | 762 | \subsection{选择默认样式为empty} 763 | 使用命令:\\ 764 | \verb+\pagestyle{empty}+\\ 765 | 也就是明确指定页眉页脚样式为已经有的样式empty,即什么都没有。现在文章所有的页眉页脚信息都被清除了。现在摆在我们面前有两条路,一条是继续DIY plain样式,然后全部页面设置为plain样式。一条是plain继续归零,然后自己DIY一个新的样式并使用这个样式。我在这里选择第一条道路了。 766 | 767 | \section{继续定制plain样式} 768 | 我不太喜欢那一条横线,有需要的请自己将前面的什么rulewidht命令横线宽度设为0.4pt左右。 769 | 770 | 我是一个喜欢简单的人,fancyhdr宏包里面还有很多命令: 771 | \vspace{-20pt} 772 | \begin{Verbatim} 773 | \lhead[]{} 774 | \chead[]{} 775 | \rhead[]{} 776 | \lfoot[]{} 777 | \cfoot[]{} 778 | \rfoot[]{} 779 | \fancyhead[selectors]{output you want} 780 | \fancyfoot[selectors]{output you want} 781 | \end{Verbatim} 782 | 这些命令都可以用fancyhf命令来达到,所以我不做介绍了,有需要的请参考fancyhdr宏包文档。 783 | 784 | \subsection{fancyhf命令的可选项} 785 | fancyhf命令的一些可选项如下表所示,比如偶数页的页眉左边位置的表示就是EHL,奇数页页脚中间位置就是OFC。本文没有区分偶数页和奇数页,而且也不想有过多的信息,比如就想页眉左边和页脚右边有点内容,那么可选项为HL和FR。 786 | \begin{table}[H] 787 | \centering 788 | \begin{tabular}{@{}ll@{}} 789 | \toprule 790 | 字母 & 意义 \\ \midrule 791 | H & 页眉(head) \\ 792 | F & 页脚(foot) \\ 793 | L & 左边(left) \\ 794 | C & 中间(center) \\ 795 | R & 右边(right) \\ 796 | E & 偶数页(even) \\ 797 | O & 奇数页(odd) \\ \bottomrule 798 | \end{tabular} 799 | \caption{fancyhf可选项字母意义} 800 | \label{tab:fancyhf可选项字母意义} 801 | \end{table} 802 | 803 | 804 | \subsection{本文页眉页脚配置代码} 805 | \begin{Verbatim} 806 | \RequirePackage{fancyhdr} %頁眉頁腳 807 | \RequirePackage{zhnumber} %计数器中文化 808 | \pagestyle{fancy} 809 | \renewcommand{\sectionmark}[1] 810 | {\markright{第\zhnumber{\arabic{section}}节~~#1}{}} 811 | 812 | \fancypagestyle{plain}{% 813 | \fancyhf{} 814 | \renewcommand{\headrulewidth}{0pt} 815 | \renewcommand{\footrulewidth}{0pt} 816 | \fancyhf[HR]{\ttfamily \footnotesize \rightmark } 817 | \fancyhf[FR]{\thepage}} 818 | \pagestyle{plain} 819 | \end{Verbatim} 820 | 821 | 首先是加载fancyhdr宏包\footnote{exam类有自己的页眉页脚定制方法,和fancyhdr宏包有冲突。}。接下来是页面风格fancy,不先这样做后面的sectionmark的重定义无效,具体原因不明。 822 | 823 | 然后接下来重定义sectionmark,这个sectionmark我不太明白,但是如果不设置\verb+\pagestyle{fancy}+它就无效,然后放在新定义的plain样式里面也会出错。 824 | 825 | 下面就是重新定制plain样式,首先是: 826 | \begin{Verbatim} 827 | % \renewcommand{\chaptermark}[1] 828 | % {\markboth{第\zhnumber{\arabic{chapter}}章~~#1}{}} 829 | % \fancyhf[HL]{\ttfamily \footnotesize \leftmark } 830 | \end{Verbatim} 831 | 为了文档简洁这些代码我都注释掉了,不过你可能用的着。这里leftmark就是目前的章名,fancyhf带上选项HL就是定义文档页眉左边的内容。然后通过修改chaptermark(如果你章节标题不自己DIY的话,这里修改chaptermark你会看到变化的。)会影响leftmark的内容。这里的markboth也是配套的。 832 | 833 | \begin{Verbatim} 834 | \fancyhf[HR]{\ttfamily \footnotesize \rightmark } 835 | \fancyhf[FR]{\thepage} 836 | \end{Verbatim} 837 | 这里的rightmark就是目前的节名,通过修改sectionmark会影响它的内容。sectionmark的重新定义如前所示是和markright命令配套的。 838 | 839 | 840 | 我起初试图如下重新定义chaptername和sectionname,然后重新定义thechapter和thesection也就是当前章节编号。在这里先将编号用arabic命令转化为1,2,3...的形式,然后用zhnumber命令(来自 \verb+zhnumber+ 宏包)转化为一,二,三...的形式。可是目录形式也跟着改变了,还有图片编号。影响范围太大了,所以就直接用上面代码的形式组合了。 841 | 842 | 843 | FR也就是右边页脚处,哪里简单填上\textbackslash thepage即表示当前页码。具体格式不用设置,请参看页码这一小节\ref{sec:页码}。 844 | 845 | \begin{Verbatim} 846 | \fancyhfoffset[R]{\marginparwidth+\marginparsep} 847 | \end{Verbatim} 848 | 最后这段代码可要可不要,作用是让页眉页脚扩展到旁注的宽度那里。放在这里,如果设置marginparwidth和marginparsep都是0pt的话,也没有什么影响的。 849 | 850 | 851 | 852 | \chapter{章节标题设计} 853 | 推荐使用\emph{titlesec}宏包进行章节标题设计,当然还有其他的宏包可以设计出更加花哨的章节标题这里忽略。 854 | 855 | \section{本文章节标题设计} 856 | \begin{Verbatim} 857 | \usepackage{titlesec} 858 | \titleformat{\part}{\huge\sffamily}{}{0em}{} 859 | \titleformat{\chapter}{\LARGE\sffamily}{}{0em}{} 860 | \titleformat{\section}{\Large\sffamily}{}{0em}{} 861 | \titleformat{\subsection}{\large\sffamily}{}{0em}{} 862 | \titleformat{\subsubsection}{\normalsize\sffamily}{}{0em}{} 863 | \end{Verbatim} 864 | 本文章节标题设计非常简单,几乎就是titleformat命令各个选项的空值。 865 | 866 | \section{titleformat命令说明} 867 | titlesec宏包还提供了其他一些命令,不过一切设置都可以通过titleformat命令来获得: 868 | \begin{Verbatim} 869 | \titleformat{\chapter}[shape]{格式}{label} 870 | {sep}{before-code}[after-code] 871 | \end{Verbatim} 872 | 第一个花括号是选择你要修改的目标,也就是是章啊,还是节啊,还是小节。从part到subparagraph都可以的。 873 | 874 | 后面是shape,一个可选项,没看懂要干嘛的。估计也不太重要吧。 875 | 876 | 第二个花括号是重点,里面放着格式命令,比如设置字体字族,字体大小,颜色等都可以的。这个格式影响后面要讲的label标签还有标题文本。\footnote{这里对齐命令,vspace命令等都是可以用的?} 877 | 878 | 第三个花括号是标签,空着就是没有标签。你也可以──比如说对于section的标题──填上\verb+\thesection+表示节的编号。 879 | 880 | 第四个花括号是标签和后面标题文字之间的空隙,这里因为没有label所以设为0了,如果有label还是加点距离。 881 | 882 | 第五个花括号和后面的可选项是什么标题盒子之前和之后的代码,这里忽略。有兴趣请参看文档。 883 | 884 | 885 | \section{章节编号数值修改} 886 | part,chapter,section等这些都是counter量,\\通过setcounter命令直接修改──比如说section──为2,那么接下来counter自动计数是从2开始,下一个section编号是3。 887 | 888 | \section{章节编号深度修改} 889 | 通过设置secnumdepth这个counter的量可以设置章节编号深度。\\ 890 | \verb+\setcounter{secnumdepth}{1} +\\ 891 | 默认是2,编号到subsection,你可以设置为3,subsubsection都有编号,或者设置为1,section有编号。我想设置为0的话section也没有编号了。 892 | 893 | \section{章节编号形式修改} 894 | \label{sec:章节编号形式修改} 895 | thepart,thechapter,thesection,thesubsection等你可以称他们为标签吧,也就是通常我们看到的编号那部分内容。通过对这些命令重定义就可以对他们进行修改了。\\ 896 | \verb+\renewcommand{\thesection}{\arabic{section}.}+\\ 897 | 那么就会有1. 的形式。 898 | 899 | \section{章节标题上插入脚注} 900 | 一般使用章节标题命令就是\verb+\section{text}+,前面还是可以加个可选项的,这个可选项的文本将作为目录中实际显示的文本,而后面则是实际执行的文本。比如:\\ 901 | \verb+\subsection[text]{{\color{red} text}\footnote{脚注}}+ 902 | \subsection[text]{{\color{red} text}\footnote{脚注}} 903 | 904 | 905 | 906 | \chapter{目录设计} 907 | 一般在封面之后插入目录,用tableofcontents命令即可。本文没有对目录做太多的修改,默认的目录格式挺好的。 908 | 909 | \section{目录深度控制} 910 | \verb+\setcounter{tocdepth}{1} +\\ 911 | tocdepth是一个counter量,默认是2,显示到subsection。这里为了是目录更加简洁,设置为了1即显示到section。0显示到chapter,-1显示part,-2就什么都没有了。 912 | 913 | \section{前言加入目录} 914 | \label{sec:前言加入目录} 915 | 本文定义了两个命令为了做到这点: 916 | \begin{Verbatim} 917 | \newcommand{\addchtoc}[1]{ %目录中加入新章节 918 | \cleardoublepage 919 | \phantomsection 920 | \addcontentsline{toc}{chapter}{#1}} 921 | \newcommand{\addsectoc}[1]{ %目录中加入新的section 922 | \phantomsection 923 | \addcontentsline{toc}{section}{#1}} 924 | \end{Verbatim} 925 | 两个命令大致类似吧,一个是针对chapter的,一个是针对section的。其中chapter的需要加上一个cleardoublepage命令,其具体解释参看\href{http://www.personal.ceu.hu/tex/breaking.htm#clrdblpage}{这个网站}。意思是首先结束本页,然后将所有图片和表格都显示出来。在两面twoside模式里,要确保下一页从奇数页开始,必要时插入空白页。 926 | 927 | 后面的phantomsection命令\footnote{这个命令名字真不好记。。}是由hyperref宏包提供的,需要加上它使链接有效。 928 | \footnote{参看了\href{http://www.forkosh.com/latex/ltx-171.html}{这个网页}} 929 | 930 | 然后addcontentsline命令就是将目前章节加入目录,第一个花括号里面的选项有:toc,lof,lot。也就是目录,图目录和表目录。第二个花括号里面如果是toc的话就是part,chapter之类的,如果是lof,好吧,一般加入label就可以了,还没接触这种情况,说不上什么。最后那个花括号里面放着要在目录上面显示的文字。 931 | 932 | 本文目录的前面加入如下命令即可:\\ 933 | \verb+\addchtoc{目录}+ 934 | 935 | 同理,参考文献处理情况类似。值得提醒的是section的时候注意换命令。 936 | 937 | \section{目录行间距拉大} 938 | 我试图建立一个通用的格式环境横跨目录的时候会失效,只好将其分开。不过这样做带来一个好处,那就是你在目录前面设置一些格式只对目录起作用。比如:\\ 939 | \verb+\addtolength{\parskip}{8pt}+\\ 940 | 这里对段落之间的间距增加了一点宽度,这个会影响一条条目录之间的行间距。 941 | 942 | 943 | \section{目录编号和标题间距调整} 944 | 如果你的目录编号,也就是前面的label和标题内容有点重叠,那么可以用tocloft宏包来自动调整目录编号和标题间距。具体代码如下: 945 | \begin{Verbatim} 946 | \RequirePackage{tocloft}% 947 | \renewcommand{\numberline}[1]{% 948 | \@cftbsnum #1\@cftasnum~\@cftasnumb% 949 | } 950 | \end{Verbatim} 951 | 952 | well,具体看不懂,不过把这段代码加上之后效果确实不错,请参考\href{http://tex.stackexchange.com/questions/64115/table-of-contents-chapter-number-width}{这个网站}。 953 | 954 | 955 | 956 | 957 | \chapter{封面设计} 958 | \section{原生的封面} 959 | 基础的封面就是用\verb+\title+输入题目,用\verb+\author+输入作者,用\verb+\date+命令输入日期,默认是输出当时编辑的日期的。然后用\verb+\maketitle+命令插入一个封面即可。 960 | 961 | 本书封面采用了极简风格,示例如下: 962 | 963 | \begin{Verbatim} 964 | \title{XeLaTeX 指南} 965 | \author{wander} 966 | 967 | 968 | %\begin{document} 969 | \maketitle 970 | 971 | \end{Verbatim} 972 | 973 | \verb+\author+里面可以用\verb+\and+命令连接几个作者或者用\textbackslash \textbackslash 命令换行,如下所示: 974 | 975 | \begin{Verbatim} 976 | \author{ 977 | a \and b \\ 978 | c 979 | } 980 | \end{Verbatim} 981 | 982 | 983 | \section{更复杂的封面设计} 984 | 我对更复杂的封面设计没有需求,下面简单介绍下思路。 985 | 986 | 可以用Latex 输出更加复杂的封面,或者用Tikz绘图来绘制出更加华丽的封面,具体请参看配置参考文件夹下面的 \verb+book_cover.tex+ 文件,利用它输出一个pdf文件,然后将其转成png文件。 987 | 988 | 然后定义如下命令: 989 | 990 | \begin{Verbatim} 991 | \newcommand{\bookcover}[1]{ 992 | \begin{titlepage} 993 | \newgeometry{left=0cm,right=0cm,top=0cm,bottom=0cm,marginparsep=0pt, 994 | marginparwidth=0em,includemp=false} 995 | \tikz[remember picture,overlay]{\node[inner sep=0] at (current page.center) 996 | {\includegraphics[width=\paperwidth,height=\paperheight]{#1}}} 997 | \end{titlepage} 998 | \restoregeometry 999 | } 1000 | \end{Verbatim} 1001 | 1002 | 这个命令就是利用tikz将你设计好的封面图片插入进来,具体如下: 1003 | 1004 | \begin{Verbatim} 1005 | \bookcover{book_cover.png} 1006 | \end{Verbatim} 1007 | 1008 | 当然你可以用其他你喜欢的任何软件或工具来生成你想要的封面,然后如上插入进来即可。 1009 | 1010 | 1011 | \chapter{引用} 1012 | \section{文章内部引用} 1013 | 某一个特别的章节图片或者表格等需要被引用时,你就在它哪里加上label命令。然后就可以用ref命令在文章内部建立链接引用他们了。值得一提的是texmaker的提示功能非常好。建立label的时候方便你管理,section部分前面就加一个sec:前缀,图片加一个fig:前缀,表格加个tab:前缀等。然后labe中文英文都是可以的,方便自己管理最好写的很明晰。 1014 | 1015 | 比如某个地方插入label: 1016 | \begin{Verbatim} 1017 | \label{ch:pandoc_epub} 1018 | \end{Verbatim} 1019 | 1020 | 然后要在引用它的地方插入: 1021 | \begin{Verbatim} 1022 | \ref{ch:pandoc_epub} 1023 | \end{Verbatim} 1024 | 1025 | 1026 | 还有一个pageref命令和ref命令差不多,文档上写法都类似,不同的是在文章上显示的是页码。 1027 | 1028 | 1029 | 1030 | \section{图表的引用} 1031 | 除开一些特殊情况,一般图表最外面是figure环境或table环境,然后在里面用 \verb+\caption+ 写上图表的标题,再后面用label命令打上标签,这样其他地方就可以用ref命令来引用了。 1032 | 1033 | \begin{Verbatim} 1034 | \caption{图表标题} 1035 | \label{fig:1-1} 1036 | \end{Verbatim} 1037 | 1038 | 值得一提的就是图表的label命令一定要在caption命令的后面,否则会定位不准确。 1039 | 1040 | 1041 | \section{hyperref宏包简介} 1042 | \subsection{如何插入超链接} 1043 | 比如这里插入一个超链接到google,\href{https://www.google.com/}{google} 。 1044 | 1045 | 首先要在前面加载hyperref库文件: 1046 | \begin{Verbatim} 1047 | \usepackage{hyperref} 1048 | \end{Verbatim} 1049 | 1050 | 1051 | 然后在你想要插入超链接的地方使用命令: 1052 | 1053 | \begin{Verbatim} 1054 | \href{https://www.google.com/}{google} 1055 | \end{Verbatim} 1056 | 1057 | 1058 | 1059 | \subsection{链接字体颜色控制} 1060 | \begin{Verbatim} 1061 | \usepackage[colorlinks=true,linkcolor=blue, 1062 | ulrcolor=red,citecolor=blue]{hyperref} 1063 | \end{Verbatim} 1064 | 1065 | \textbf{colorlinks=ture}是把颜色打开,如果是false那么都是默认的黑色了。后面的选项主要影响文字颜色,还有更多颜色设置。linkcolor影响目录颜色和脚注和内部引用,ulrcolor影响对外链接,citecolor影响对文献的链接。anchorcolor超链接源码。 1066 | 1067 | hyperref宏包目前我的DIY只限于一些颜色设置,更多信息请参阅官方文档。 1068 | 1069 | \subsection{设置pdf的元数据} 1070 | 如下设置pdf的元数据,这样生成的pdf导入到carlibre软件中,一些必要的信息会自动填充上去。 1071 | 1072 | \begin{Verbatim} 1073 | \hypersetup{ 1074 | pdftitle={XeLaTeX 指南}, 1075 | pdfauthor={wander}, 1076 | pdfsubject={计算机.文档开发}, 1077 | } 1078 | \end{Verbatim} 1079 | 1080 | 1081 | \chapter{脚注} 1082 | 加入脚注还是很有用的\footnote{这就是一个脚注}。具体方法就是: 1083 | 1084 | \begin{Verbatim} 1085 | \footnote{这就是一个脚注} 1086 | \end{Verbatim} 1087 | 1088 | 1089 | \section{脚注标签修改} 1090 | 重定义thefootnote命令会影响每一条脚注前面的label样式,比如默认的1.。 1091 | \begin{Verbatim} 1092 | \renewcommand{\thefootnote}{\arabic{footnote}} 1093 | \end{Verbatim} 1094 | 1095 | 1096 | \section{一页脚注重新编号} 1097 | 我喜欢每一页脚注都重新编号,觉得那些数字反正也没什么意义。具体实现如下代码所示。 1098 | \begin{Verbatim} 1099 | \usepackage{perpage} 1100 | \MakePerPage{footnote} 1101 | \end{Verbatim} 1102 | 1103 | 1104 | \section{脚注中的距离} 1105 | \begin{itemize} 1106 | \item \verb+\footnotesep+,长度量, 控制脚注与脚注之间的距离。 1107 | \item \verb+\skip\footins+,长度量,控制正文和脚注之间的距离。 1108 | \end{itemize} 1109 | 1110 | 1111 | \section{重定义脚注文本格式} 1112 | \begin{Verbatim} 1113 | \renewcommand\@makefntext[1]{\vspace{5pt}\noindent 1114 | \makebox[20pt][c]{\fontsize{10pt}{12pt}\@thefnmark} 1115 | \fontsize{10pt}{12pt}\selectfont #1} 1116 | \end{Verbatim} 1117 | 1118 | 这里重新定义了(在sty文件中)\verb+\@makefntext+命令,命令的参数就是每一条脚注的内容的。 1119 | 1120 | 1121 | \section{表格里的脚注} 1122 | \href{http://texblog.org/tag/footnote/}{参考了这个网站},具体实现过程很简单,就是表格放入minipage环境下即可直接使用脚注命令了。 1123 | 1124 | \begin{Verbatim} 1125 | \begin{minipage}{6cm} 1126 | \begin{tabular}{|l|c|c|} 1127 | \hline 1128 | A & 1 & 2 \footnote{This is a footnote.} \\ 1129 | \hline 1130 | B & 2 & 1 \\ 1131 | \hline 1132 | C & 3 & 3 \\ 1133 | \hline 1134 | \end{tabular} 1135 | \end{minipage} 1136 | \end{Verbatim} 1137 | 1138 | 1139 | \begin{minipage}{6cm} 1140 | \begin{tabular}{|l|c|c|} 1141 | \hline 1142 | A & 1 & 2 \footnote{This is a footnote.} \\ 1143 | \hline 1144 | B & 2 & 1 \\ 1145 | \hline 1146 | C & 3 & 3 \\ 1147 | \hline 1148 | \end{tabular} 1149 | \end{minipage} 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | \chapter{文字强调} 1156 | \section{emph命令} 1157 | emph命令一般是英文换成斜体,中文换成楷体(也就是前面设置的意大利字形的字体)。不过不同字族会有不同的表现。如果在强调环境之内有强调(一般没有这种情况把。)那么文字又会换成常规形态。 1158 | emph命令是\LaTeX 自带的最基本的用于文字强调的方法。 1159 | 1160 | 1161 | \section{重新定义emph} 1162 | \label{sec:emph} 1163 | 本文档中的emph命令被重新定义了: 1164 | \begin{Verbatim} 1165 | \renewcommand{\emph}[1]{\textcolor{blue}{\textbf{#1}}} 1166 | \end{Verbatim} 1167 | 1168 | 比如:\emph{我觉得字体设为蓝色加粗更加起到强调作用} 。这样重新定义emph命令是能够正确处理中文换行问题的。 1169 | 1170 | \section{underline命令} 1171 | 这个也是\LaTeX 自带的命令,就是加上下划线,不过在中文中并不能正确换行。所以请往下看。 1172 | 1173 | \section{ulem宏包} 1174 | 也不知道从什么时候开始ulem的uline命令中文不能正确换行了,还有一个很老的解决方案什么CJKulem宏包个人试了一下也并不可行,在xecjk宏包中发现了解决方案,其还提供了一个子宏包 \textbf{xeCJKfntef} ,可以将之前引入ulem宏包的命令删除了,xeCJKfntef是依赖ulem宏包的,然后加载之: 1175 | 1176 | \section{xeCJKfntef宏包} 1177 | \begin{Verbatim} 1178 | \RequirePackage{xeCJKfntef} 1179 | \end{Verbatim} 1180 | 1181 | ulem宏包原来的命令: uline,uuline,uwave,sout, xout等等都是支持的,这个宏包还提供了一些额外的命令这里就略过讨论了。 1182 | 1183 | \uline{这是一段很长的测试文字,主要用于说明中文情况下加入下划线并且能够正确的换行。用的是uline命令。} 1184 | 1185 | 1186 | 1187 | \chapter{插入列表} 1188 | itemize和enumerate环境其实也支持item后面跟上可选项的形式,只是从格式上他们常常出界,不建议使用。 1189 | \section{基本使用} 1190 | \subsection{itemize环境} 1191 | \begin{Verbatim} 1192 | \begin{itemize} 1193 | \item 这是一个列表 1194 | \item 这又是一个列表 1195 | \end{itemize} 1196 | \end{Verbatim} 1197 | 1198 | 1199 | \begin{itemize} 1200 | \item 这是一个列表 1201 | \item 这又是一个列表 1202 | \end{itemize} 1203 | 1204 | 1205 | 1206 | \subsection{enumerate环境} 1207 | \begin{Verbatim} 1208 | \begin{enumerate} 1209 | \item 这是一个列表 1210 | \item 这又是一个列表 1211 | \end{enumerate} 1212 | \end{Verbatim} 1213 | 1214 | \begin{enumerate} 1215 | \item 这是一个列表 1216 | \item 这又是一个列表 1217 | \end{enumerate} 1218 | 1219 | \subsection{description环境} 1220 | \begin{Verbatim} 1221 | \begin{description} 1222 | \item[鸭子]是一种动物 1223 | \item[苹果]是红色的 1224 | \end{description} 1225 | \end{Verbatim} 1226 | \begin{description} 1227 | \item[鸭子]是一种动物 1228 | \item[苹果]是红色的 1229 | \end{description} 1230 | 1231 | \section{enumerate环境标签的修改} 1232 | \label{sec:enumerate环境标签的修改} 1233 | enumerate环境中各个item标签自动生成是依赖各个对应的计数器,然后通过labelenumi,labelenumii,labelenumiii和labelenumiv这几个命令控制的,也就是重新定义这些命令,标签样式就被修改了。这几个中最常用的是第一级标签labelenumi,下面就这个命令给出例子。 1234 | 1235 | 首先我希望这个enumerater环境的item计数从0开始,然后我希望它的格式是<0>。 1236 | 1237 | \begin{figure}[H] 1238 | \centering 1239 | \includegraphics[scale=1 , keepaspectratio]{enumerate_1.png} 1240 | \end{figure} 1241 | 1242 | 1243 | 1244 | 上面的实现实际tex代码如下所示: 1245 | \begin{Verbatim} 1246 | \begin{enumerate} 1247 | \setcounter{enumi}{-1} 1248 | \renewcommand{\labelenumi}{<\arabic{enumi}>} 1249 | \item 这是一个列表 1250 | \item 这又是一个列表 1251 | \end{enumerate} 1252 | \end{Verbatim} 1253 | 1254 | 估计计数器使用的时候都会先加一,所以为了初值为0,只好先设置为-1了。 1255 | 1256 | 1257 | 再举个例子,假设你已经加载了 \textbf{zhnumber} 包了,那么我们可以实现中文中常见的那种罗列环境: 1258 | 1259 | \begin{figure}[H] 1260 | \centering 1261 | \includegraphics[scale=1 , keepaspectratio]{enumerate_2.png} 1262 | \end{figure} 1263 | 1264 | 1265 | 上面的实现实际tex代码如下所示: 1266 | 1267 | \begin{Verbatim} 1268 | \begin{enumerate} 1269 | \renewcommand{\labelenumi}{\zhnumber{\arabic{enumi}}.} 1270 | \item 这是一个列表 1271 | \item 这又是一个列表 1272 | \end{enumerate} 1273 | \end{Verbatim} 1274 | 1275 | 1276 | \section{itemize环境标签的修改} 1277 | itemize环境里面当然没有计数器,不过它类似的也有:\\ labelitemi,labelitemii等命令,通过重定义这些命令就可以影响第一级第二级等标签样式。 1278 | 1279 | 1280 | 1281 | 1282 | \chapter{插入图片} 1283 | 要插入一个图片,\LaTeX 文档开头那里要加载库文件: 1284 | \begin{Verbatim} 1285 | \usepackage{graphicx} 1286 | \end{Verbatim} 1287 | 1288 | 1289 | 然后在你想要插入图片的地方输入如下命令: 1290 | \begin{Verbatim} 1291 | \includegraphics[scale=1]{图像名字} 1292 | \end{Verbatim} 1293 | 1294 | 1295 | 插入图片有很多参数可以设置,这里就最有用的宽度和高度设置说明一下。具体就是height表示高度,width表示宽度。然后等于多少in(英寸)。参数放在可选参数那里。不过我觉得下面这个参数设置挺实用的,如下: 1296 | 1297 | \begin{Verbatim} 1298 | \includegraphics[width=\textwidth, keepaspectratio]{test.png} 1299 | \end{Verbatim} 1300 | 1301 | 其中\textbackslash textwidth 表示让图片和文本内容区块一般宽,后面经过摸索发现使用linewidth可能更好,因为在多栏环境下linewidth就是那栏的宽度,但这具体读者自己决定了。然后keepaspectratio参数意思是缩放的时候保持宽高比不变。 1302 | 1303 | \section{图片标签的修改} 1304 | \label{sec:图片标签的修改} 1305 | 本文的图片环境标题通过输入 \verb+\caption{text}+ 即实现如下形式的图片标题:\verb+图 1-1: text+ 。 1306 | 1307 | 其中图这个字是通过重定义figurename命令来完成的。 1308 | 1309 | \begin{Verbatim} 1310 | \renewcommand\figurename{图} 1311 | \end{Verbatim} 1312 | 1313 | 1314 | 而后面本来默认的是1.1这样的形式,但是常见的都是1-1这样的形式,通过重定义thefigure命令即可达到目的。 1315 | 1316 | \begin{Verbatim} 1317 | \renewcommand{\thefigure}{\arabic{chapter}-\arabic{figure}} 1318 | \end{Verbatim} 1319 | 1320 | \subsection{取消图片标签} 1321 | 有时候通过caption插入图片标题,前面的标签你不想要。这个时候就算将thefigure命令设置为控制还是会有“图:”这两个文字,如果这两个你都不想要。推荐用caption宏包的\verb+caption*+命令,那个命令完全没有标签,写成什么样子显示就是什么样子。不过要注意的是caption宏包提供的\verb+caption*+命令会让该图表没有进入编号,这可能不是你想要的。 1322 | 1323 | 1324 | \section{设置图片寻找文件夹} 1325 | 如下的命令设置,这样\TeX 会自动在这些文件夹寻找文件,也就是你在include图片时直接写上图片文件名即可。这个语句是支持多个文件夹设置的。 1326 | 1327 | \begin{Verbatim} 1328 | \graphicspath{{figures/}} 1329 | \end{Verbatim} 1330 | 1331 | 1332 | 1333 | \section{图片格式的讨论} 1334 | \subsection{支持的图片文件格式} 1335 | 使用xelatex和graphicx宏包,目前我测试支持的图片格式有:eps,png,jpg,pdf。 1336 | 1337 | 1338 | \subsection{搜索图片后缀名控制} 1339 | 经测试上面的eps,png,jpg,pdf格式的图片后缀名默认都支持,也就是只要写上前面的文件名即可。 1340 | 1341 | 1342 | \section{本文常使用的插入图片代码片段} 1343 | 1344 | \begin{Verbatim} 1345 | \begin{figure}[H] 1346 | \centering 1347 | \includegraphics[scale=1 , keepaspectratio]{fig_name.png} 1348 | \end{figure} 1349 | \end{Verbatim} 1350 | 1351 | \begin{Verbatim} 1352 | \begin{figure}[H] 1353 | \centering 1354 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , 1355 | keepaspectratio]{fig_name.png} 1356 | \end{figure} 1357 | \end{Verbatim} 1358 | 1359 | 上面第一个插入图片例子缩放 \verb+scale=1+ ,这对于那些尺寸较小的图片有不错的显示效果。如果图片较大的话,那么就可以考虑使用第二个代码片段,其使用了 \verb+width=\linewidth+ 来让图片自动适应你的文档的linewidth(之所以选择linewidth是因为在多栏环境下也会自动适应到那个栏的宽度。)。 1360 | 1361 | \section{图表的浮动控制} 1362 | 现代电子书籍在作风上和传统纸质书籍还是有一些区别的,一般来说是推荐使用float宏包提供的 \verb+H+ 选项来达到一种类似网页显示的瀑布流风格\footnote{除了极个别的情况,比如跨几页的表格。},这种浮动控制有时会产生一小段空白,问题其实不大,只有在纸质书籍上才会计较这些。 1363 | 1364 | 此外在布局上,不是太推荐那种图片文字杂糅的多变动风格布局,文字叙述和图表之间不易固定,布局多变内容位置没有固定有时是会产生一些不便的。 1365 | 1366 | 1367 | 1368 | \chapter{插入表格} 1369 | \section{基本情况的讨论} 1370 | 一般情况下一些小的表格就用tabular环境处理即可。 1371 | 下面看这个例子: 1372 | \begin{Verbatim} 1373 | \begin{table}[h] 1374 | \centering 1375 | \begin{tabular}{|c|c|} 1376 | \hline 1377 | l & l表示该列格子左对齐 \\ 1378 | \hline 1379 | c & c表示该列格子居中 \\ 1380 | \hline 1381 | r & r表示该列格子右对齐 \\ 1382 | \hline 1383 | \end{tabular} 1384 | \caption{tabular参数} 1385 | \label{tab:tabular参数} 1386 | \end{table} 1387 | \end{Verbatim} 1388 | 1389 | 例子显示如下: 1390 | \begin{table}[H] 1391 | \centering 1392 | \begin{tabular}{|c|c|} 1393 | \hline 1394 | l & l表示该列格子内容左对齐 \\ 1395 | \hline 1396 | c & c表示该列格子内容居中 \\ 1397 | \hline 1398 | r & r表示该列格子内容右对齐 \\ 1399 | \hline 1400 | \end{tabular} 1401 | \caption{tabular参数} 1402 | \label{tab:tabular参数} 1403 | \end{table} 1404 | 在table环境那里我加了一个可选参数h,意思是在这里就在这里。这个表格还有图片环境都是什么浮动体。我们看到他们可以加上caption命令从而有一个标题,然后table和figure后面有个可选参数来控制这个浮动体的位置。默认是tbp。不过我喜欢用h,也就是在这里如果可能。有的时候h的表现效果可能不太让你满意。那么你可以尝试float宏包,它提供了H参数,会更加强制地控制浮动体,H的意思是一定要在这里。 1405 | 1406 | 这段代码中centering命令是让表格居中。caption命令是加上标题,label命令是方便引用。 1407 | 1408 | 最重要的就是tabular环境,前面|符号表示画一个竖线,也就是每一列刚开始画一条竖线,你也可以不画表示每一列开始不画竖线。然后是字母c,表示每一列第一个格子居中对齐,类似的还有字母l(left)和r(right)。还有一种格式p{width},表示该格子具有width的宽度,然后里面的文字自动断行。 1409 | 1410 | hline命令表示画一条横线。\& 这个特殊符号表示进入下一列。\textbackslash \textbackslash 表示进入下一行,后面跟上可选项距离,那么下一行的高度将拉高。 1411 | 1412 | 1413 | \section{booktabs宏包} 1414 | 如果你只是想要一个简洁明了的表格,目前大家公认的好的表格标准就是三线表式,你也可以称之为booktabs风格吧。简单来说有以下规则\footnote{按照Markus Püschel的small guide to making nice tables里面的介绍。}: 1415 | 1416 | \begin{enumerate} 1417 | \item 不要垂直线 1418 | \item 不要双横线 1419 | \item 每一行的各个格子都有足够的空间 1420 | \item 一律左对齐 1421 | \item 三线,toprule,midrule,bottomrule 1422 | \end{enumerate} 1423 | 1424 | 1425 | 在这里我们还有个捷径\footnote{texmaker编辑器的向导菜单那里有个表格向导方便快速生成表格tex代码片段。},不一定要手工将表格代码全部敲出来。首先我们找一个表格软件,libreoffice的或者gnumeric都行。然后将数据输入进去保存好。然后我们将数据选择复制,打开网站:\href{http://www.tablesgenerator.com/}{www.tablesgenerator.com} ,在那个网站的表格的开头哪里按下Ctrl+v。这个网站还有一些设置可以调整,稍微摸索下就知道了。唯一要说的是那个activate/deactivate custom grid edit选项,可以选择绘制某几根线框显示。在这里不做调整,直接选择最右边的booktabs table style。然后把多余的行或者列删除掉,就可以点击下面的generate了。生成的代码如下: 1426 | \begin{Verbatim} 1427 | \begin{table}[h] 1428 | \begin{tabular}{@{}ll@{}} 1429 | \toprule 1430 | 参数 & 描述 \\ \midrule 1431 | l & 左对齐 \\ 1432 | c & 居中 \\ 1433 | r & 右对齐 \\ 1434 | p{width} & 一定宽度自动换行 \\ \bottomrule 1435 | \end{tabular} 1436 | \end{table} 1437 | \end{Verbatim} 1438 | 表格的显示效果初步如下: 1439 | \footnote{你注意到这里有@\{\},意思是每一列前面有一段空白,可以被花括号中的字符填充,这里是完全取消掉那点空白。booktabs的风格是开头那点空白和最后一列最后那点空白全部取消掉。} 1440 | \begin{table}[H] 1441 | \begin{tabular}{@{}ll@{}} 1442 | \toprule 1443 | 参数 & 描述 \\ \midrule 1444 | l & 左对齐 \\ 1445 | c & 居中 \\ 1446 | r & 右对齐 \\ 1447 | p{width} & 一定宽度自动换行 \\ \bottomrule 1448 | \end{tabular} 1449 | \end{table} 1450 | 1451 | 接下来就是微调整了,比如说上面的花括号没有正常显示,还有想要居中,开头加上centering命令,还有caption标题命令,还有label。修改之后结果如下: 1452 | \begin{table}[H] 1453 | \centering 1454 | \begin{tabular}{@{}ll@{}} 1455 | \toprule[1.2pt] 1456 | 参数 & 描述 \\ \midrule 1457 | l & 左对齐 \\ 1458 | c & 居中 \\ 1459 | r & 右对齐 \\ 1460 | p\{width\} & 一定宽度自动换行 \\ \bottomrule[1.2pt] 1461 | \end{tabular} 1462 | \caption{tabular参数-2} 1463 | \label{tab:tabular参数-2} 1464 | \end{table} 1465 | 1466 | \section{一个三线表模板} 1467 | 这是一个简单的三线表模板,你可以在texmaker或者其他编辑器里面设置好快速插入代码片段的功能。然后快速输入一下代码块,然后填上数据,这样就很快捷了。 1468 | \begin{Verbatim} 1469 | \begin{table}[H] 1470 | \centering 1471 | \label{tab:} 1472 | \caption{} 1473 | \medskip 1474 | \begin{tabular}{@{}ll@{}} 1475 | \toprule 1476 | 选项 & 说明 \\ \midrule 1477 | H & 页眉(head) \\ 1478 | O & 奇数页(odd) 1479 | \\ \bottomrule 1480 | \end{tabular} 1481 | \end{table} 1482 | \end{Verbatim} 1483 | 1484 | 1485 | \section{booktabs宏包详解} 1486 | 上面已经算是一个booktabs风格的表格了,为了进一步深度定制这里对booktabs宏包做一些说明。 1487 | 1488 | \subsection{线条粗细} 1489 | 前面我们看到了booktabs宏包新加了三个命令toprule,midrule和bottomrule。这三个命令后面都可以跟个可选项调整线条粗细。后面跟的参数1pt就表示线条粗1pt,没有加法的意思。上面的例子中toprule和bottomrule设置为1.2pt,比原来的稍微粗了一点。嫌麻烦不改动也可以,觉得原来的也还好。 1490 | 1491 | 1492 | \section{longtable宏包} 1493 | 特别长的表格推荐使用longtable宏包,它虽然在使用上有点类似booktabs宏包,但外面就不要加上table环境封装了,caption和label都跟在后面,都是很长的表格了,一定要跨页了,table的那一套浮动控制也不适用它了。就直接使用longtable环境即可。 1494 | 1495 | 你可能希望长表格的行间距缩小一些,用前面讨论的arraystretch方法局部作用即可。 1496 | 1497 | \begin{Verbatim} 1498 | { 1499 | \renewcommand{\arraystretch}{0.8} 1500 | \begin{longtable}{|c|c|} 1501 | ... 1502 | \end{longtable} 1503 | } 1504 | \end{Verbatim} 1505 | 1506 | 更多细节请参看官方文档。 1507 | 1508 | 1509 | 1510 | \chapter{插入代码} 1511 | \section{小代码} 1512 | 有的时候一行之内的小代码就不需要大动干戈用verbatim环境,用\\ 1513 | \verb| \verb+ 这里放着小代码 + |,这里的+号可以换成其他任何的符号表示小代码开始和结束,除了*和空格不行。 1514 | 1515 | 带星号的verb有其他用途,在里面空格以符号显示出来了,比如:\\ 1516 | \verb*| this is a test . | 。 1517 | 1518 | 在Verbatim环境或者verb命令之内,字体是ttfamily。 1519 | 1520 | 1521 | 1522 | \section{稍微大点的程序代码} 1523 | 在环境verbatim之间的任何文本是什么就是什么,不执行任何\LaTeX 命令,包括所有的空白和断行,如下: 1524 | 1525 | \begin{verbatim} 1526 | (defmacro with-gensyms (syms &rest body) 1527 | `(let ,(mapcar #'(lambda (s) 1528 | `(,s (gensym))) 1529 | syms) 1530 | ,@body)) 1531 | \end{verbatim} 1532 | 1533 | 1534 | 1535 | 1536 | \section{fancyvrb宏包} 1537 | fancyverb宏包提供了一个Verbatim环境,比如下面的配置代码的说明如下。更多说明请参见fancyvrb宏包文档。 1538 | 1539 | \begin{Verbatim} 1540 | \fvset{numbers=left,frame=lines,tabsize=4 ,baselinestretch=2, 1541 | xleftmargin=6pt, fontsize=\footnotesize , numbersep=2pt} 1542 | \end{Verbatim} 1543 | 1544 | \begin{table}[H] 1545 | \centering 1546 | \caption{Verbatim环境一些设置} 1547 | \label{tab:Verbatim环境一些设置} 1548 | \medskip 1549 | \begin{tabular}{@{}ll@{}} 1550 | \toprule 1551 | 配置 & 说明 \\ \midrule 1552 | numbers=left & 左边显示数字 \\ 1553 | frame=lines & 框框是两条线 \\ 1554 | tabsize=4 & tab符号是四个空格 \\ 1555 | baselinestretch=2 & 行间距拉伸 \\ 1556 | xleftmargin=6pt & 左边间距6pt \\ 1557 | fontsize=\textbackslash footnotesize & 字体大小设置 \\ 1558 | numbersep=2pt & 数字和框框间距 \\ \bottomrule 1559 | \end{tabular} 1560 | \end{table} 1561 | 1562 | \subsection{引入外部文件} 1563 | 如果用input命令引入外部文件,除非这个文件就是原生的tex格式,否则一般会出错,也即是如果你想将外部脚本的运行结果引入进来,最好还是引入到代码环境里面。fancyvrb提供了 \textit{VerbatimInput} 命令,可能是你想要的。 1564 | 1565 | 1566 | \section{minted宏包} 1567 | 本小节简要介绍下minted宏包的使用,更多信息请参看官方文档。 1568 | 1569 | minted宏包是利用pygments来进行语法染色,它还提供了一个listings环境,不过并不能正确分页,所以让我们忘了那个listings环境(或者现在问题解决了?),然后就其他部分,自动语法染色,fancyvrb DIY选项的继承,还新增了背景颜色的设置,这些都是极好的。 1570 | 1571 | \textbf{注意}:不管你在那个系统,要正确使用这个宏包系统中都必须要有pygmentize这个命令,也就是你要安装python的pygments这个模块。即: 1572 | 1573 | \begin{Verbatim} 1574 | pip install pygments 1575 | \end{Verbatim} 1576 | 1577 | \subsection{mint命令} 1578 | minted宏包提供了mint命令来进行inline的code输入,这正好弥补了原verb命令功能过于简陋的问题。 1579 | 1580 | \begin{Verbatim} 1581 | \mint{tex}+\test code+ 1582 | \end{Verbatim} 1583 | 1584 | 注意:mint命令里面不能再写上mint命令。 1585 | 1586 | \subsection{minted环境} 1587 | \begin{Verbatim} 1588 | \begin{minted}{c} 1589 | #include 1590 | 1591 | int main(void) 1592 | { 1593 | printf("hello, world\n"); 1594 | return 0; 1595 | } 1596 | \end{minted} 1597 | \end{Verbatim} 1598 | 1599 | \begin{minted}{c} 1600 | #include 1601 | 1602 | int main(void) 1603 | { 1604 | printf("hello, world\n"); 1605 | return 0; 1606 | } 1607 | \end{minted} 1608 | 1609 | minted宏包加上背景颜色会出现hbox的badness问题。 1610 | 1611 | \subsection{引入外部文件} 1612 | minted宏包提供了 \textit{inputminted} 命令来引入外部文件到minted环境中。 1613 | 1614 | 一个简单的例子如下所示,其中label选项可以在开头显示具体的引入文件名,或者你想要显示的其他信息。 1615 | 1616 | \begin{Verbatim} 1617 | \def\source{filename.py} 1618 | \inputminted[label=\source]{python}{\source} 1619 | \end{Verbatim} 1620 | 1621 | 1622 | \chapter{特殊文字环境} 1623 | \section{语录和引用环境} 1624 | \LaTeX 原生的有quote为语录环境,quotation用于超过几段的引用环境,verse用于诗歌环境。 1625 | 1626 | 1627 | \subsection{语录环境演示} 1628 | \begin{Verbatim} 1629 | \begin{quote} 1630 | some text 1631 | \end{quote} 1632 | \end{Verbatim} 1633 | 1634 | 1635 | \begin{quote} 1636 | “When the winds of change blow, some people build walls and others build windmills.” 1637 | \end{quote} 1638 | 1639 | \subsection{引用环境演示} 1640 | \begin{Verbatim} 1641 | \begin{quotation} 1642 | some text 1643 | 1644 | some text 1645 | \end{quotation} 1646 | \end{Verbatim} 1647 | 1648 | 1649 | \begin{quotation} 1650 | 说Unix必将衰败,或者被其他操作系统挤出市场。可是在今天,化身Linux、BSD、Solaris、MacOS X以及好几种其它变种的Unix,却显得前所未有的强大。 1651 | 1652 | Robert Metcalf[以太网络的发明者]曾说过:如果将来有什么技术来取代以太网,那么这个取代物的名字还会叫“以太网”。因此以太网是永远不会消亡的Unix也多次经历了类似的转变。 1653 | \end{quotation} 1654 | 1655 | 1656 | \section{定制quote和quotation环境} 1657 | \label{sec:quotation_huan_jing_ding_zhi} 1658 | 1659 | 以下讨论参考了\href{http://tex.stackexchange.com/questions/33219/whats-the-difference-between-the-environments-quote-and-quotation}{这个网站} 。 1660 | 1661 | quote和quotation在article.cls中的原初定义是这样的: 1662 | \begin{Verbatim} 1663 | \newenvironment{quote} 1664 | {\list{}{\rightmargin\leftmargin}% 1665 | \item\relax} 1666 | {\endlist} 1667 | \newenvironment{quotation} 1668 | {\list{}{\listparindent 1.5em% 1669 | \itemindent \listparindent 1670 | \rightmargin \leftmargin 1671 | \parsep \z@ \@plus\p@}% 1672 | \item\relax} 1673 | {\endlist} 1674 | \end{Verbatim} 1675 | 1676 | 我改成了如下: 1677 | \begin{Verbatim} 1678 | %=========重新定义 quote=====% 1679 | \renewenvironment{quote}[1][anonymous] 1680 | {\def\quoteauthor{#1} 1681 | \list{}{\rightmargin\leftmargin %右间距等于左间距 1682 | \itemindent 2em 1683 | }\item\relax 1684 | \ttfamily} 1685 | {\\ 1686 | \makebox[\linewidth][r]{\sffamily —\quoteauthor} 1687 | \endlist} 1688 | 1689 | 1690 | %重新定义quotation 1691 | \renewenvironment{quotation} 1692 | {\list{}{\rightmargin\leftmargin %右间距等于左间距 1693 | \itemindent 2em%item的缩进也就是第一段的缩进 1694 | \listparindent \itemindent %第二段的缩进 1695 | }% 1696 | \item\relax 1697 | \ttfamily} 1698 | {\endlist} 1699 | \end{Verbatim} 1700 | 1701 | quote重新定义那里需要def定义\verb+\quoteauthor+ 命令来将作者名传递到环境收尾动作那里。用newcommand在pandoc输出epub时会报警。 1702 | 1703 | quote和quotation都是通过list环境来实现的,具体不太清楚。这里就我做的修改说明如下: 1704 | \begin{itemize} 1705 | \item \verb+\rightmargin\leftmargin+这是让右边空白距离等于左边空白距离,左边空白距离默认等于\verb+\parindent+,这个有用我保留了。 1706 | \item \verb+\itemindent 2em+,这个itemindent控制的是第一段的段首缩进量,这里设置为2em即两个字符的意思。 1707 | \item 代码第七行是设置quote环境下字体为ttfamily。 1708 | \item quote环境后面的代码,在结束环境之前,先换行,然后输出了一个盒子,右对齐,ssfamily,写着这个格言的作者,因为格言一般都要写上作者,如果不知道那么也写上anonymous,无名氏。这个作者的名字是quote环境接受一个可选项而来的额。 1709 | \item \verb+\listparindent \itemindent+,quotation多了一个这个设置,其中listparindent是控制quotation里面除了第一段之外其他段落的缩进,这里就简单设置为跟第一段一样。 1710 | \item quotation环境的其他修改,parsep是控制段与段之间距离的,这里取消了,因为默认的就很好了。 1711 | \end{itemize} 1712 | 1713 | \section{简单的线框包围环境} 1714 | framed宏包提供了一个简单的线框包围环境。跨页测试没有问题,有些时候可能就想要这样一个简单的线框包围环境,因为其他复杂的环境里面七七八八各种Tex命令,干扰因素会很多。 1715 | 1716 | \begin{Verbatim} 1717 | \begin{framed} 1718 | 样例文字. 1719 | \end{framed} 1720 | \end{Verbatim} 1721 | 1722 | 1723 | \begin{framed} 1724 | 这里参考了Knuth的The Texbook,但是我并没有将其写入参考文献,因为只是觉得关于box和glue的概念最好参考原初定义,但是并不推荐读者阅读这本书,现在已经是\LaTeX 时代了,不推荐读者使用原始的\TeX 命令,一是不太实用,二是兼容性可能不太好。除非你是宏包编写者,但就作为一般的使用者真的没有必要接触那些原始命令了。还参考了\cite{boxes} 1725 | \end{framed} 1726 | 1727 | 1728 | \section{mdframed宏包} 1729 | 线框包围大段文字 \verb+mdframed+ 宏包提供了很好的跨页支持,内置的 \verb+\fbox+ 和 \verb+\fcolorbox+ 会有问题的,此外mdframed的解决方案相比tcolorbox更轻量级一些\footnote{tcolorbox这个宏包非常的重。},如果使用mdframed的话里面的文字显示效果和格式等是不受破坏的,对于大段大段引用其他书籍的情况,mdframed宏包更合适一些。 1730 | 1731 | 更多内容请参看mdframed宏包的官方文档,下面是一些个人定制代码: 1732 | 1733 | \begin{Verbatim} 1734 | \RequirePackage{mdframed} 1735 | \mdfsetup{frametitlealignment=\center} 1736 | \newmdenv[frametitlebackgroundcolor=gray!20, linewidth=1pt, 1737 | frametitlerulewidth=1pt, frametitlerule=true]{bookref} 1738 | \end{Verbatim} 1739 | 1740 | 使用代码如下: 1741 | \begin{Verbatim} 1742 | \begin{bookref}[frametitle={\cite{黄帝内经}}] 1743 | [黄帝]乃问于天师曰:余闻上古之人,春秋皆度百岁,而动作不衰;... 1744 | 1745 | ...... 1746 | \end{bookref} 1747 | \end{Verbatim} 1748 | 1749 | 显示效果如下: 1750 | 1751 | \begin{bookref}[frametitle={\cite{黄帝内经}}] 1752 | [黄帝]乃问于天师曰:余闻上古之人,春秋皆度百岁,而动作不衰;今时之人,年半百而动作皆衰者,时世异耶,人将失之耶? 1753 | 1754 | 歧伯对曰:上古之人,其知道者,法于阴阳,和于术数,食饮有节,起居有常,不妄作劳,故能形与神俱,而尽终其天年,度百岁乃去。今时之人不然也,以酒为浆,以妄为常,醉以入房,以欲竭其精,以耗散其真,不知持满,不时御神,务快其心,逆于生乐,起居无节,故半百而衰也。夫上古圣人之教下也,皆谓之虚邪贼风,避之有时,恬惔虚无,真气从之,精神内守,病安从来。是以志闲而少欲,心安而不惧,形劳而不倦,气从以顺,各从其欲,皆得所愿。故美其食,任其服,乐其俗,高下不相慕,其民故曰朴。是以嗜欲不能劳其目,淫邪不能惑其心,愚智贤不肖不惧于物,故合于道。所以能年皆度百岁而动作不衰者,以其德全不危也。 1755 | \end{bookref} 1756 | 1757 | mdframed似乎对数学上的定义和定理提供了比较好的展示效果,这个可能在数学公式那一章中会讨论。 1758 | 1759 | 1760 | 1761 | 1762 | \section{诗词歌赋环境} 1763 | 本文新建了一个shici环境,在原verse环境下稍微做了一些修改,具体如下所示: 1764 | \begin{Verbatim} 1765 | \newenvironment{shici}{ 1766 | \begin{verse} 1767 | \centering\large\hspace{12pt}} 1768 | {\end{verse}} 1769 | \end{Verbatim} 1770 | 1771 | 1772 | 在诗歌环境里面不会自动换行,需要手动输入\verb+\\+。 1773 | 1774 | 1775 | \begin{Verbatim} 1776 | \begin{shici} 1777 | 孤鸿海上来,池潢不敢顾。\\ 1778 | 侧见双翠鸟,巢在三珠树。\\ 1779 | 矫矫珍木巅,得无金丸惧。\\ 1780 | 美服患人指,高明逼神恶。\\ 1781 | 今我游冥冥,弋者何所慕。 1782 | \end{shici} 1783 | \end{Verbatim} 1784 | 1785 | 1786 | \begin{shici} 1787 | 孤鸿海上来,池潢不敢顾。\\ 1788 | 侧见双翠鸟,巢在三珠树。\\ 1789 | 矫矫珍木巅,得无金丸惧。\\ 1790 | 美服患人指,高明逼神恶。\\ 1791 | 今我游冥冥,弋者何所慕。 1792 | \end{shici} 1793 | 1794 | 1795 | 1796 | 1797 | \chapter{数学公式} 1798 | Tex 提供的数学公式支持非常有用,在html5那边有Mathjax,其底层也支持Tex 命令的数学公式。 1799 | 1800 | 现在一般都会引入amssymb和amsmath宏包,有时要区分那些命令是Tex原生的那些是它们提供的多少有点繁琐了,本文假定现在数学输入环境上都已经加载这两个宏包了。 1801 | 1802 | 数学公式的输入可以在网上找一个在线latex公式编辑器,但Tex输入公式并没有那么复杂,学会一些基本的东西之后,大部分情况都是能够快速应对的,只是某些极个别的符号可能会不知道怎么输入。 1803 | 1804 | 符号参考可以在 \href{http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf}{官方完全Latex符号列表} 或者 \href{http://latex.wikia.com/wiki/List_of_LaTeX_symbols}{list of latex symbols} 查看。 1805 | 1806 | \section{数学输入环境} 1807 | \verb+$ $+包围起来的是行内(inline)的数学公式;\verb+\[ \]+ 包围起来的是独立成一段的数学公式,其是displaymath环境的简写形式。 1808 | 1809 | \begin{Verbatim} 1810 | \begin{displaymath} 1811 | 1812 | \end{displaymath} 1813 | \end{Verbatim} 1814 | 1815 | \textbf{NOTICE}: 现在数学行间环境已经不推荐使用 \verb+$$ ... $$+ 了。 1816 | 1817 | \subsection{单个公式的行间数学环境} 1818 | \emph{equation}环境就是有编号的单公式行间数学环境。 1819 | 1820 | 无用的知识:前面说了行间数学环境用 \verb+\[ ... \]+ ,其等于displaymath环境,amsmath宏包还提供了equation*环境,它没有编号,实际上只是一个别名,仍等于displaymath环境。 1821 | 1822 | \begin{Verbatim} 1823 | \begin{equation} 1824 | a+b+c+d+e+f 1825 | \end{equation} 1826 | \end{Verbatim} 1827 | 1828 | \begin{equation} 1829 | a+b+c+d+e+f 1830 | \end{equation} 1831 | 1832 | \emph{multiline}环境类似equation环境,区别是单个公式太长了,可以换行来多行显示。 1833 | 1834 | \begin{Verbatim} 1835 | \begin{multline} 1836 | a+b+c+d+e+f\\ 1837 | +i+j+k+l+m+n\\ 1838 | +o+p+q+r+s 1839 | \end{multline} 1840 | \end{Verbatim} 1841 | 1842 | \begin{multline} 1843 | a+b+c+d+e+f\\ 1844 | +i+j+k+l+m+n\\ 1845 | +o+p+q+r+s 1846 | \end{multline} 1847 | 1848 | 1849 | 1850 | 1851 | \subsection{多个公式的行间数学环境} 1852 | \emph{gather}和\emph{align}是多个公式有编号的行间数学环境,如果加上星号,那么就是多个公式无编号的行间数学环境。 1853 | 1854 | \begin{Verbatim} 1855 | \begin{gather} 1856 | a_1=b_1+c_1\\ 1857 | a_2=b_2+c_2-d_2+e_2 1858 | \end{gather} 1859 | \end{Verbatim} 1860 | 1861 | 1862 | \begin{gather} 1863 | a_1=b_1+c_1\\ 1864 | a_2=b_2+c_2-d_2+e_2 1865 | \end{gather} 1866 | 1867 | gather默认是居中对齐,align环境可以通过加上 \verb+&+ 来指定对齐位置,比如下面通过各个等号的对齐来展示一系列的推导过程: 1868 | 1869 | \begin{Verbatim} 1870 | \begin{align} 1871 | P_1 &= \frac{v}{2} + \frac{w}{2} - (\frac{3v}{4} + \frac{w}{4}) \\ 1872 | &= -\frac{1}{4}v + \frac{w}{4} \\ 1873 | &= \frac{1}{4}(w-v) 1874 | \end{align} 1875 | \end{Verbatim} 1876 | 1877 | \begin{align} 1878 | P_1 &= \frac{v}{2} + \frac{w}{2} - (\frac{3v}{4} + \frac{w}{4}) \\ 1879 | &= -\frac{1}{4}v + \frac{w}{4} \\ 1880 | &= \frac{1}{4}(w-v) 1881 | \end{align} 1882 | 1883 | 下面展示\emph{align*}无编号情况。 1884 | 1885 | \begin{Verbatim} 1886 | \begin{align*} 1887 | P_1 &= \frac{v}{2} + \frac{w}{2} - (\frac{3v}{4} + \frac{w}{4}) \\ 1888 | &= -\frac{1}{4}v + \frac{w}{4} \\ 1889 | &= \frac{1}{4}(w-v) 1890 | \end{align*} 1891 | \end{Verbatim} 1892 | 1893 | \begin{align*} 1894 | P_1 &= \frac{v}{2} + \frac{w}{2} - (\frac{3v}{4} + \frac{w}{4}) \\ 1895 | &= -\frac{1}{4}v + \frac{w}{4} \\ 1896 | &= \frac{1}{4}(w-v) 1897 | \end{align*} 1898 | 1899 | 1900 | 如果希望多个公式组如上对齐并只有一个编号,可以使用\emph{aligned}环境外面再加上equation环境: 1901 | 1902 | \begin{Verbatim} 1903 | \begin{equation} 1904 | \begin{aligned} 1905 | P_1 &= \frac{v}{2} + \frac{w}{2} - (\frac{3v}{4} + \frac{w}{4}) \\ 1906 | &= -\frac{1}{4}v + \frac{w}{4} \\ 1907 | &= \frac{1}{4}(w-v) 1908 | \end{aligned} 1909 | \end{equation} 1910 | \end{Verbatim} 1911 | 1912 | \begin{equation} 1913 | \begin{aligned} 1914 | P_1 &= \frac{v}{2} + \frac{w}{2} - (\frac{3v}{4} + \frac{w}{4}) \\ 1915 | &= -\frac{1}{4}v + \frac{w}{4} \\ 1916 | &= \frac{1}{4}(w-v) 1917 | \end{aligned} 1918 | \end{equation} 1919 | 1920 | amsmath还有更多的环境和其他选项控制等,请参看官方文档。 1921 | 1922 | 1923 | 1924 | \section{数学的label和ref} 1925 | 在数学环境里面加入标签:一般格式是\verb+\label{eq:4.1}+ 1926 | 1927 | 然后引用是\verb+(\ref{eq:4.1})+,外面加个括号好看点。 1928 | 1929 | 数学公式的引用推荐使用eqref命令: \verb+\eqref{...}+ ,这样你就不需要手动输入外面的括号组了。 1930 | 1931 | 1932 | \section{加入文本} 1933 | 使用text命令可以在数学环境中正常输入一些文本(包括中文,如果你已经处理好中文显示问题了。) 1934 | 1935 | 1936 | \section{空白距离} 1937 | 数学环境里面的所有空白距离和换行都被忽略了。需要用命令手动生成。如下所示,这几个命令生成的间隔逐渐加大。 1938 | 1939 | 1940 | 1941 | \begin{Verbatim} 1942 | \begin{align*} 1943 | &**\\ 1944 | &*\,*\\ 1945 | &*\:*\\ 1946 | &*\;*\\ 1947 | &*\quad*\\ 1948 | &*\qquad* 1949 | \end{align*} 1950 | \end{Verbatim} 1951 | 1952 | \begin{align*} 1953 | &**\\ 1954 | &*\,*\\ 1955 | &*\:*\\ 1956 | &*\;*\\ 1957 | &*\quad*\\ 1958 | &*\qquad* 1959 | \end{align*} 1960 | 1961 | 1962 | \section{常见格式} 1963 | \begin{itemize} 1964 | \item 分数:\verb+\frac{x}{m}+ $\frac{x}{m}$ 1965 | \item 上标: \verb+{x}^{m}+ ${x}^{m}$ 1966 | \item 下标:\verb+{x}_{m}+ ${x}_{m}$ 1967 | \item 谁的上面:\verb+\overset{a}{x}+ $\overset{a}{x}$ 1968 | \item 谁的下面:\verb+\underset{b}{x}+ $\underset{b}{x}$ 1969 | \item 谁的上面和下面:\verb+\overunderset{a}{b}{x}+ $\overunderset{a}{b}{x}$ 1970 | \item 根号: \verb+\sqrt[x]{m}+ $ \sqrt[x]{m} $ 1971 | \end{itemize} 1972 | 1973 | 1974 | \section{函数} 1975 | 特定的函数要写成对应的命令形式,下面简单列出一些: 1976 | 1977 | \begin{Verbatim} 1978 | \begin{gather*} 1979 | \sin \cos \sec \tan \tanh \arccos \arctan %三角函数 1980 | \exp %指数函数 1981 | \min \max % 最小最大 1982 | \lim %极限 1983 | \log \ln \lg % 对数函数相关 1984 | \gcd % 最大公约数 1985 | \end{gather*} 1986 | \end{Verbatim} 1987 | 1988 | \begin{gather*} 1989 | \sin \cos \sec \tan \tanh \arccos \arctan \\ 1990 | \exp \\ 1991 | \min \max \\ 1992 | \lim \\ 1993 | \log \ln \lg \\ 1994 | \gcd \\ 1995 | \end{gather*} 1996 | 1997 | 比如: 1998 | \begin{Verbatim} 1999 | \[ 2000 | \lim_{x\to\infty}f(x) 2001 | \] 2002 | \end{Verbatim} 2003 | 2004 | \[ 2005 | \lim_{x\to\infty}f(x) 2006 | \] 2007 | 2008 | 极限还可以写为下面的形式: 2009 | 2010 | \begin{Verbatim} 2011 | \[ 2012 | \underset{x\to\infty}{\lim}f(x) 2013 | \] 2014 | \end{Verbatim} 2015 | 2016 | \[ 2017 | \underset{x\to\infty}{\lim}f(x) 2018 | \] 2019 | 2020 | 这两个并不能说那个是错的,但一般来说会推荐更简单的形式,所以有下面一小节常见的表达的讨论。 2021 | 2022 | \section{常见的表达} 2023 | 通过前面的学习,你可能心里有了一些该怎么输入某些数学公式的想法,但有一些常见的表达有如下推荐做法: 2024 | 2025 | \begin{itemize} 2026 | \item 对数:\verb+\ln_{x}{m}+ $\ln_{x}{m}$ 2027 | \item 极限:\verb+\lim_{x\to\infty}+ $\lim_{x\to\infty}$ 2028 | \item 求和:\verb+\sum_{i=1}^{n}x_i+ $\sum_{i=1}^{n}x_i$ 2029 | \item 乘积:\verb+\prod_{i=1}^{n}x_i+ $\prod_{i=1}^{n}x_i$ 2030 | \item 某个变量的变体:\verb+x'+ $x'$ 就是单引号直接写上 2031 | \item 那个无理数 $e$ 是的,直接在数学模式下输入e即可,在费曼物理学讲义网站确认了,可见这个常数是如此的重要和特殊,竟然自己直接独占一个常用的小写字母。然后常说的 $\exp$函数实际上就是 $e^x$ ,也就是以 $e$ 为底的指数函数。 2032 | \item 积分: \verb+\int_{a}^{b}\sin x+ $\int_{a}^{b}\sin x$ 2033 | 2034 | \end{itemize} 2035 | 2036 | 2037 | \section{分段函数} 2038 | \begin{Verbatim} 2039 | $ 2040 | y = |x| = 2041 | \begin{cases} 2042 | x, & x \geqslant 0,\\ 2043 | -x, & x<0. 2044 | \end{cases} 2045 | $ 2046 | \end{Verbatim} 2047 | 2048 | 2049 | $ 2050 | y = |x| = 2051 | \begin{cases} 2052 | x, & x \geqslant 0,\\ 2053 | -x, & x<0. 2054 | \end{cases} 2055 | $ ,cases环境是amsmath包提供的。 2056 | 2057 | 2058 | \section{常用数学符号} 2059 | 除了上面谈及的,下面是额外的一些还比较常用的数学符号的表示,这些确实非常常用,汇总在这里了。 2060 | \begin{itemize} 2061 | \item 乘 $\times$ \verb+\times+ 2062 | \item 除 $\div$ \verb+\div+ 2063 | \item 正负 $\pm$ \verb+\pm+ 2064 | \item 圆周率 $\pi$ \verb+\pi+ 2065 | \item 两个矢量的点积 $\cdot$ \verb+\cdot+ 【参考了 \href{http://www.feynmanlectures.caltech.edu/I_13.html}{费曼物理学讲义网站},其描述功就是使用的力矢量和位移矢量的点积】高中教材更加粗的那个点应该是使用的 \verb+\bullet+ $\bullet$ 。 2066 | \item 无穷大 $\infty$ \verb+\infty+ 2067 | \item 正比 $\propto$ \verb+\propto+ 2068 | \item oint $\oint_{m}^{x}b$ \verb+\oint_{m}^{x}b+ 2069 | \item 对于所有 $ \forall $ \verb+\forall+ 2070 | \item 所以 $ \therefore $ \verb+\therefore+ 2071 | \end{itemize} 2072 | 2073 | \section{常用箭头符号} 2074 | 函数定义为从集合A到集合B的一个映射: $f: A \rightarrow B$ ,这几个箭头应该很常用: 2075 | 2076 | \begin{itemize} 2077 | \item 向右箭头 $\rightarrow$ \verb+\rightarrow+ 2078 | \item 向左箭头 $\leftarrow$ \verb+\leftarrow+ 2079 | \item 宽向右箭头 $\Rightarrow$ \verb+\Rightarrow+ 2080 | \item 宽向左箭头 $\Leftarrow$ \verb+\Leftarrow+ 2081 | \item 宽左右箭头 $\Leftrightarrow$ \verb+\Leftrightarrow+ 2082 | \item 向上箭头 $\uparrow$ \verb+\uparrow+ 2083 | \item 向下箭头 $\downarrow$ \verb+\downarrow+ 2084 | \item 宽向上箭头 $\Uparrow$ \verb+\Uparrow+ 2085 | \item 宽向下箭头 $\Downarrow$ \verb+\Downarrow+ 2086 | \end{itemize} 2087 | 2088 | 向右箭头在极限中可以写为 \verb+\to+ $\to$ ,但实际上就是向右箭头。 2089 | 2090 | \section{不同的括号包围} 2091 | \begin{itemize} 2092 | \item \verb+\left(x\right)+ $\left(x\right)$ 2093 | \item \verb+\left|x\right|+ $\left|x\right|$ 2094 | \item \verb+\left[x\right]+ $\left[x\right]$ 2095 | \item \verb+\left\{x\right\}+ $\left\{x\right\}$ 2096 | \item \verb+\left\langle x\right\rangle+ $\left\langle x\right\rangle$ 2097 | \item \verb+\left\| x \right\| + $\left\| x \right\| $ 2098 | \end{itemize} 2099 | 2100 | 除了一些简单的单行行间数学环境,可以不写上\verb+\left...\right+ ,其他的一般都推荐带上,来避免一些显示问题,请看下面的讨论。 2101 | 2102 | \subsection{括号放大对比带上left命令} 2103 | 括号放大命令罗列如下,逐渐放的更大: 2104 | \begin{itemize} 2105 | \item \verb+\big+ 2106 | \item \verb+\Big+ 2107 | \item \verb+\bigg+ 2108 | \item \verb+\Bigg+ 2109 | \end{itemize} 2110 | 2111 | 如下例子演示了,这个公式起初看起来花括号太小了,然后试着通过放大花括号,但终于最好的效果还是带上left命令的那个。 2112 | 2113 | 2114 | \begin{Verbatim} 2115 | \[ 2116 | B=\{ y|y\geqslant \frac{4ac - b^2}{4a} \} 2117 | \] 2118 | 2119 | \[ 2120 | B=\big\{ y|y\geqslant \frac{4ac - b^2}{4a} \big\} 2121 | \] 2122 | 2123 | \[ 2124 | B=\Big\{ y|y\geqslant \frac{4ac - b^2}{4a} \Big\} 2125 | \] 2126 | 2127 | \[ 2128 | B=\left\{ y|y\geqslant \frac{4ac - b^2}{4a} \right\} 2129 | \] 2130 | \end{Verbatim} 2131 | 2132 | \[ 2133 | B=\{ y|y\geqslant \frac{4ac - b^2}{4a} \} 2134 | \] 2135 | 2136 | \[ 2137 | B=\big\{ y|y\geqslant \frac{4ac - b^2}{4a} \big\} 2138 | \] 2139 | 2140 | \[ 2141 | B=\Big\{ y|y\geqslant \frac{4ac - b^2}{4a} \Big\} 2142 | \] 2143 | 2144 | \[ 2145 | B=\left\{ y|y\geqslant \frac{4ac - b^2}{4a} \right\} 2146 | \] 2147 | 2148 | 2149 | 2150 | \section{不同的数学字体} 2151 | 不同的数学字体演示如下,读者简单了解下即可,具体用什么字体在数学那边很多情况下都是有规范和特定含义的。 2152 | 2153 | \begin{itemize} 2154 | \item \verb+ABCDE+ $ABCDE$ 2155 | \item \verb+\mathbf{ABCDE}+ $\mathbf{ABCDE}$ 2156 | \item \verb+\mathrm{ABCDE}+ $\mathrm{ABCDE}$ 2157 | \item \verb+\mathsf{ABCDE}+ $\mathsf{ABCDE}$ 2158 | \item \verb+\mathit{ABCDE}+ $\mathit{ABCDE}$ 2159 | \item \verb+\mathcal{ABCDE}+ $\mathcal{ABCDE}$ 2160 | \item \verb+\mathbb{ABCDE}+ $\mathbb{ABCDE}$ 2161 | \item \verb+\mathfrak{ABCDE}+ $\mathfrak{ABCDE}$ 2162 | \end{itemize} 2163 | 2164 | 2165 | 2166 | 2167 | \section{集合} 2168 | 一般的 $x-7<3$ 直接写就是了,然后有时我们看到中间三个点的应该属于中文的标点符号,不过用数学模式来写问题不大:\verb+$\cdots$+ $\cdots$ 。 2169 | 2170 | 1~20以内的的所有质数中间的波浪号应该属于中文符号,数学模式下类似的中间一个波浪号的可以用 \verb+$\sim$+ $\sim$ 来画出来,从命令的名字来看其应该更多的用于描述两个三角形相似性之类的关系上。 2171 | 2172 | 元素a属于集合A,a is member of A 2173 | 2174 | \begin{Verbatim} 2175 | \[ 2176 | a \in A 2177 | \] 2178 | \end{Verbatim} 2179 | 2180 | \[ 2181 | a \in A 2182 | \] 2183 | 2184 | a不属于A, 2185 | 2186 | \begin{Verbatim} 2187 | \[ 2188 | a \notin A 2189 | \] 2190 | \end{Verbatim} 2191 | 2192 | \[ 2193 | a \notin A 2194 | \] 2195 | 2196 | 2197 | 列举法写出某个集合,这里关键是 \{ 花括号在 \LaTeX 中是特殊符号,所以前面要加个左斜杠符号。 \verb+$\{1,2,3\}$+ $\{1,2,3\}$ 。 2198 | 2199 | 我们看到人教版高中教材并没有严格遵守这种数学排版约定(这里说的是这些特殊含义的集合),而是采用实心粗体,而通常这种实心粗体是推荐用来表示物理学中的矢量的。 2200 | 2201 | 描述法来描述一个集合,所有奇数的集合: 2202 | 2203 | \begin{Verbatim} 2204 | \[ 2205 | E = \{x \in \mathbb{Z} | x = 2k + 1, k \in \mathbb{Z}\} 2206 | \] 2207 | \end{Verbatim} 2208 | 2209 | \[ 2210 | E = \{x \in \mathbb{Z} | x = 2k + 1, k \in \mathbb{Z}\} 2211 | \] 2212 | 2213 | \subsection{常见的数集} 2214 | \begin{description} 2215 | \item[自然数集] \verb+$\mathbb{N}$+ $\mathbb{N}$ 【0是否属于自然数是有点争议的,这不是本文讨论的内容。】 2216 | \item[正整数集] \verb+$\mathbb{N}^{*}$+ $\mathbb{N}^{*}$ 2217 | \item[整数集] \verb+$\mathbb{Z}$+ $\mathbb{Z}$ 2218 | \item[有理数集] \verb+$\mathbb{Q}$+ $\mathbb{Q}$ 2219 | \item[实数集] \verb+$\mathbb{R}$+ $\mathbb{R}$ 2220 | \item[复数集] \verb+$\mathbb{C}$+ $\mathbb{C}$ 2221 | \end{description} 2222 | 2223 | 2224 | 实际上所有大写字母,看上去中间有些空的那种符号,都可以 \\ 2225 | \verb+$\mathbb{A}$+ $\mathbb{A}$ 来获得。 2226 | 2227 | NOTICE: mathbb命令需要本文档加载 amssymb 包。 2228 | 2229 | \subsection{集合的关系} 2230 | 如果集合A中的任何一个元素都是集合B中的元素,我们说A是B的子集,记作 2231 | 2232 | \begin{Verbatim} 2233 | \[ 2234 | A \subseteq B 2235 | \] 2236 | \end{Verbatim} 2237 | 2238 | \[ 2239 | A \subseteq B 2240 | \] 2241 | 2242 | 或者说 B 包含 A,记作: 2243 | 2244 | \begin{Verbatim} 2245 | \[ 2246 | B \supseteq A 2247 | \] 2248 | \end{Verbatim} 2249 | 2250 | \[ 2251 | B \supseteq A 2252 | \] 2253 | 2254 | 两个集合相等就直接用 = 即可。 2255 | 2256 | 如果集合A包含于B,但存在元素属于B而不属于A,我们称A是B的真子集,记作: 2257 | 2258 | 2259 | \begin{Verbatim} 2260 | \[ 2261 | A \subsetneqq B 2262 | \] 2263 | \end{Verbatim} 2264 | 2265 | \[ 2266 | A \subsetneqq B 2267 | \] 2268 | 2269 | 或者: 2270 | 2271 | \begin{Verbatim} 2272 | \[ 2273 | B \supsetneqq A 2274 | \] 2275 | \end{Verbatim} 2276 | 2277 | \[ 2278 | B \supsetneqq A 2279 | \] 2280 | 2281 | 我记得真子集我读书的时候是用下面这两个符号来表示的,不是下面加上一个不等于号,就是没有等于号表示不相等。 2282 | 2283 | 2284 | \begin{Verbatim} 2285 | \[ 2286 | A \subset B 2287 | \] 2288 | \end{Verbatim} 2289 | 2290 | \[ 2291 | A \subset B 2292 | \] 2293 | 2294 | 或者: 2295 | 2296 | \begin{Verbatim} 2297 | \[ 2298 | B \supset A 2299 | \] 2300 | \end{Verbatim} 2301 | 2302 | \[ 2303 | B \supset A 2304 | \] 2305 | 2306 | 按照简单性原则,和参看 \href{https://www.rapidtables.com/math/symbols/Basic_Math_Symbols.html#lnkset}{这个网页} ,真子集我是推荐后面的方案。 2307 | 2308 | 空集: 2309 | 2310 | \begin{Verbatim} 2311 | \[ 2312 | \emptyset 2313 | \] 2314 | \end{Verbatim} 2315 | 2316 | \[ 2317 | \emptyset 2318 | \] 2319 | 2320 | 上面的空集按照命令的字面意思是推荐使用 emptyset 这个命令的,但可能有时你会觉得 varnothing命令显示效果会更好一点吧。 2321 | 2322 | \begin{Verbatim} 2323 | \[ 2324 | \varnothing 2325 | \] 2326 | \end{Verbatim} 2327 | 2328 | \[ 2329 | \varnothing 2330 | \] 2331 | 2332 | 2333 | \subsection{集合的运算} 2334 | A和B之间的并集记作: 2335 | 2336 | \begin{Verbatim} 2337 | \[ 2338 | A \cup B 2339 | \] 2340 | \end{Verbatim} 2341 | 2342 | \[ 2343 | A \cup B 2344 | \] 2345 | 2346 | 也许并集符号像个杯子所以记作cup吧。 2347 | 2348 | A和B之间的交集记作: 2349 | 2350 | \begin{Verbatim} 2351 | \[ 2352 | A \cap B 2353 | \] 2354 | \end{Verbatim} 2355 | 2356 | \[ 2357 | A \cap B 2358 | \] 2359 | 2360 | 而cap是帽子的意思。 2361 | 2362 | 全集 universe set ,按照上面的描述,那种中间有点空的字体表示某种特殊的集合,所以全集的表示为: 2363 | 2364 | \begin{Verbatim} 2365 | \[ 2366 | \mathbb{U} 2367 | \] 2368 | \end{Verbatim} 2369 | 2370 | \[ 2371 | \mathbb{U} 2372 | \] 2373 | 2374 | 补集 complement set 有的说是要在上面带个C字母, $A^{C}$ 或者 如教材上这种写法: $C_{\mathbb{U}}A$ ,都可以把。 2375 | 2376 | 2377 | 2378 | 2379 | 2380 | \section{向量} 2381 | 用粗体字母来表示向量:\verb+\mathbf{v}+ $ \mathbf{v} $ 。 2382 | 2383 | 2384 | 有的地方会用上面带个小箭头来表示向量(或者只是物理上用来表示矢量?)这是可以用\textbf{vec}命令和\textbf{overrightarrow}命令。其中vec命令只适用一个字母的情况。 2385 | 2386 | $\vec{a} \quad \overrightarrow{BC}$ 2387 | 2388 | 2389 | \subsection{矢量} 2390 | 比如物理上力的矢量表示(以区分力的分量$ F_x $),则需要符号加粗。\verb+\boldsymbol{F}+ 2391 | $ \boldsymbol{F} $ 。 2392 | 2393 | 2394 | 总的来说个人推荐物理学上表示力的矢量推荐用 boldsymbol 命令来封装,而数学意义上的某个向量则推荐用 mathbf 命令来封装\footnote{参考amsmath官方文档9.3小节,mathbf通常用于数学环境下的拉丁字母加粗显示,但是对于其他数学符号是没有效果的,正因为如此amsmath宏包才又提供了boldsymbol来应对那些没有效果的情况,如果该符号在你的数学字体集(math font set)下是有粗体的话。}。 2395 | 2396 | 2397 | \section{矩阵} 2398 | 可以是一个类似矩阵的格式,只是外面没有括号包围: 2399 | 2400 | \begin{Verbatim} 2401 | \[ 2402 | \begin{matrix} 2403 | 1 & 2 & 3\\ 2404 | a & b & c 2405 | \end{matrix} 2406 | \] 2407 | \end{Verbatim} 2408 | 2409 | \[ 2410 | \begin{matrix} 2411 | 1 & 2 & 3\\ 2412 | a & b & c 2413 | \end{matrix} 2414 | \] 2415 | 2416 | 再结合上面讨论的不同的括号包围,从而构成了矩阵。 2417 | 2418 | \begin{Verbatim} 2419 | \[ 2420 | \left[ 2421 | \begin{matrix} 2422 | 1 & 2 & 3\\ 2423 | a & b & c 2424 | \end{matrix} 2425 | \right] 2426 | \] 2427 | \end{Verbatim} 2428 | 2429 | \[ 2430 | \left[ 2431 | \begin{matrix} 2432 | 1 & 2 & 3\\ 2433 | a & b & c 2434 | \end{matrix} 2435 | \right] 2436 | \] 2437 | 2438 | 2439 | 在熟悉amsmath宏包提供的 \emph{bmatrix},\emph{pmatrix},\emph{Bmatrix},\emph{vmatrix},\emph{Vmatrix} 各个环境命令之后,就推荐用这些环境命令来书写矩阵了。 2440 | 2441 | \begin{Verbatim} 2442 | \[ 2443 | \begin{bmatrix} 2444 | 1 & 2 & 3\\ 2445 | a & b & c 2446 | \end{bmatrix} 2447 | \] 2448 | \end{Verbatim} 2449 | 2450 | \[ 2451 | \begin{bmatrix} 2452 | 1 & 2 & 3\\ 2453 | a & b & c 2454 | \end{bmatrix} 2455 | \] 2456 | 2457 | 2458 | \begin{Verbatim} 2459 | \[ 2460 | \begin{pmatrix} 2461 | 1 & 2 & 3\\ 2462 | a & b & c 2463 | \end{pmatrix} 2464 | \] 2465 | \end{Verbatim} 2466 | 2467 | \[ 2468 | \begin{pmatrix} 2469 | 1 & 2 & 3\\ 2470 | a & b & c 2471 | \end{pmatrix} 2472 | \] 2473 | 2474 | \begin{Verbatim} 2475 | \[ 2476 | \begin{Bmatrix} 2477 | 1 & 2 & 3\\ 2478 | a & b & c 2479 | \end{Bmatrix} 2480 | \] 2481 | \end{Verbatim} 2482 | 2483 | \[ 2484 | \begin{Bmatrix} 2485 | 1 & 2 & 3\\ 2486 | a & b & c 2487 | \end{Bmatrix} 2488 | \] 2489 | 2490 | 2491 | 2492 | \begin{Verbatim} 2493 | \[ 2494 | \begin{vmatrix} 2495 | 1 & 2 & 3\\ 2496 | a & b & c 2497 | \end{vmatrix} 2498 | \] 2499 | \end{Verbatim} 2500 | 2501 | \[ 2502 | \begin{vmatrix} 2503 | 1 & 2 & 3\\ 2504 | a & b & c 2505 | \end{vmatrix} 2506 | \] 2507 | 2508 | \begin{Verbatim} 2509 | \[ 2510 | \begin{Vmatrix} 2511 | 1 & 2 & 3\\ 2512 | a & b & c 2513 | \end{Vmatrix} 2514 | \] 2515 | \end{Verbatim} 2516 | 2517 | \[ 2518 | \begin{Vmatrix} 2519 | 1 & 2 & 3\\ 2520 | a & b & c 2521 | \end{Vmatrix} 2522 | \] 2523 | 2524 | 2525 | 2526 | \section{大于等于之类的符号} 2527 | 大于和小于直接键盘输入就是了,大于等于之类的符号如下命令输入之。 2528 | 2529 | 大于等于之类的符号如下所示: 2530 | 2531 | \begin{itemize} 2532 | \item 大于等于 $\geqslant$ \verb+\geqslant+ 2533 | 2534 | \item 约等于 $\approx$ \verb+\approx+ 2535 | 2536 | \item 小于等于 $\leqslant$ \verb+\leqslant+ 2537 | 2538 | \item 不等于 $\neq$ \verb+\neq+ 2539 | 2540 | \item 相似于 $\sim$ \verb+\sim+ 2541 | \end{itemize} 2542 | 2543 | 似乎国外的教材大于等于或者小于等于常用的符号是: 2544 | 2545 | \begin{itemize} 2546 | \item 大于等于 $\geq$ \verb+\geq+ 2547 | \item 小于等于 $\leq$ \verb+\leq+ 2548 | \end{itemize} 2549 | 2550 | \section{希腊字母} 2551 | \begin{table}[H] 2552 | \resizebox{\linewidth}{!}{ 2553 | \begin{tabular}{|l|l|l|l|l|l|l|l|l|l|} 2554 | \hline 2555 | $\alpha$ & alpha &$\beta$ & beta & $\gamma$ & gamma & $\delta$ & delta &$\epsilon$ & epsilon \\ 2556 | $\zeta$ & zeta &$\eta$ & eta & $\theta$ & theta & $\iota$ & iota &$\kappa$ & kappa \\ 2557 | $\lambda$ & lambda &$\mu$ & mu & $\nu$ & nu & $\xi$ & xi &$\pi$ & pi \\ 2558 | $\rho$ & rho &$\sigma$ & sigma & $\tau$ & tau & $\upsilon$ & upsilon &$\phi$ & phi \\ 2559 | $\chi$ & chi &$\psi$ & psi & $\omega$ & omega & $\digamma$ & digamma &$\varepsilon$ & varepsilon \\ 2560 | $\varkappa$ & varkappa &$\varphi$ & varphi & $\varpi$ & varpi & $\varrho$ & varrho &$\varsigma$ & varsigma \\ 2561 | $\vartheta$ & vartheta &$\Gamma$ & Gamma & $\Delta$ & Delta & $\Lambda$ & Lambda &$\Phi$ & Phi \\ 2562 | $\Pi$ & Pi &$\Psi$ & Psi & $\Sigma$ & Sigma & $\Theta$ & Theta &$\Upsilon$ & Upsilon \\ 2563 | $\Xi$ & Xi &$\Omega$ & Omega & & & & & & \\ 2564 | \hline 2565 | \end{tabular} 2566 | } 2567 | \end{table} 2568 | 2569 | 2570 | 2571 | 2572 | \subsection{几何相关} 2573 | 2574 | \begin{itemize} 2575 | \item 两条直线平行 平行符号似乎应该推荐时 $AB \parallel CD$ \verb+$AB \parallel CD$+ 。高中教材采用的那个斜平行符号比较冷门,翻了符号表才找到:$AB \sslash CD$ \verb+$AB \sslash CD$+ 。 \textbf{NOTICE:} sslash命令要额外加载 \textbf{stmaryrd} 包,还有个 varparallel 命令,也是不能直接使用的,感觉挺麻烦的,若没有特别需要,就用 parallel 命令来描述平行关系吧。 2576 | 2577 | \item 两条直线垂直 $AB \perp CD$ \verb+$AB \perp CD$+ (perpendicular) 2578 | \item 且使 $\angle x' O' y' = 45^{\circ}$ 这里角度 $\angle$ \verb+\angle+ ,度°是用的 \verb+$\circ$+ ,你需要用上标写法把这个符号送上去 2579 | 2580 | \item 我们说三角形ABC $\Delta ABC$ ,那个表示三角形的符号实际上就是希腊大写字母Delta: \verb+\Delta+ 2581 | 2582 | 2583 | \end{itemize} 2584 | 2585 | 2586 | 2587 | \section{表达式上下加上额外的符号} 2588 | 2589 | \subsection{表达式上划线或者下划线} 2590 | 就是\textbf{overline}命令和\textbf{underline}命令。此外还有一个bar命令,但bar命令只适合一个小写字母情况的上划线情况,如这样 $\bar{a}$ \verb+$\bar{a}$+ ,其他情况即使是大写字母也不行。 2591 | 2592 | \begin{Verbatim} 2593 | $\overline{x+y}$ $\underline{\frac{2}{3}}$ 2594 | \end{Verbatim} 2595 | 2596 | $\overline{x+y}$ $\underline{\frac{2}{3}}$ 2597 | 2598 | 对于统计学上的样本均值就是使用的这里的overline命令:\\ 2599 | $\overline{X}$ \verb+$\overline{X}$+ 。 2600 | 2601 | 2602 | \subsection{表达式上或下有个大括号} 2603 | 使用\textbf{overbrace}和\textbf{underbrace}命令。 2604 | 2605 | \begin{Verbatim} 2606 | $\underbrace{ a+b+\cdots+z }_{26}$ 2607 | \end{Verbatim} 2608 | 2609 | $\underbrace{ a+b+\cdots+z }_{26}$ 2610 | 2611 | 2612 | 2613 | 2614 | 2615 | 2616 | 2617 | \chapter{参考资料} 2618 | 正式出版物尤其是paper会对参考文献的格式有严格的要求,但我没有这个需求,个人会更加喜好一种偏口语化表达的形式。下面只讲最基本的参考文献环境知识,其他高级bibtex知识暂不谈论。 2619 | 2620 | 首先设置\textbf{thebibliography}环境,然后用\textbf{bibitem}命令插入文献,这里99的意思是编号宽度不超过99\footnote{实际显示的编号。}。在你想要引用的地方用cite命令\footnote{之前谈及,比如这里就是\textbackslash cite\{latex123\}}。具体格式如下所示: 2621 | 2622 | \begin{Verbatim} 2623 | \begin{thebibliography}{9} 2624 | \bibitem{latex123} 《大家来学\LaTeX 》,原版作者:李果正。 2625 | \end{thebibliography} 2626 | \end{Verbatim} 2627 | 2628 | bibitem命令的必填参数是参考文献的标签名字,但不是实际显示的名字,默认是显示的编号。如果你需要控制实际显示的文本名字是什么那么可以用可选项来控制之。如\verb+\bibitem[what]{latex123}+。这样处理之后文章中用cite命令简单引用这篇文献,那么显示的文本也将变成“what”,而不是编号。 2629 | 2630 | 后面要插入文献的引用,就使用cite命令,参数是该文献引用名,比如上面就是latex123。比如这里我插入了一个参考文献的引用,是用的是cite命令。\\ 2631 | \verb+ \cite{latex123}+请参见文献\cite{latex123} 2632 | 2633 | 2634 | 2635 | 2636 | \part{xelatex进阶} 2637 | \chapter{颜色} 2638 | \label{sec:颜色} 2639 | \section{颜色的心理学} 2640 | 颜色心理学是一门学问,这里不会深究,只是在文档里面字体或者背景使用什么颜色是一门大学问。这里主要参照\href{http://www.jb51.net/article/8216.htm}{这个网站}简单说下。本文定义的几个颜色也是参考的这个网站。 2641 | 2642 | \begin{description} 2643 | \item[红色] 一种激奋的色彩。刺激效果,能使人产生冲动,愤怒,热情,活力的感觉。 2644 | \item[绿色] 介于冷暖两中色彩的中间,显得和睦,宁静,健康,安全的感觉。 它和金黄,淡白搭配,可以产生优雅,舒适的气氛。 2645 | \item[橙色] 也是一种激奋的色彩,具有轻快,欢欣,热烈,温馨,时尚的效果。 2646 | \item[黄色] 具有快乐,希望,智慧和轻快的个性,它的明度最高。 2647 | \item[蓝色] 是最具凉爽,清新,专业的色彩。它和白色混合,能体现柔顺,淡雅,浪漫的气氛(像天空的色彩:) 2648 | \item[白色] 具有洁白,明快,纯真,清洁的感受。 2649 | \item[黑色] 具有深沉,神秘,寂静,悲哀,压抑的感受。 2650 | \item[灰色] 具有中庸,平凡,温和,谦让,中立和高雅的感觉。    2651 | \end{description} 2652 | 2653 | 2654 | 2655 | 2656 | \section{颜色配置} 2657 | 首先推荐使用xcolor宏包。在\href{http://tex.stackexchange.com/questions/89763/when-to-use-the-xcolor-package-instead-of-the-color-package}{这个网页}里,谈到原color宏包的所有特性基本上xcolor都支持,同时又加了很多新特性,相当于扩充集吧。 2658 | 2659 | 这里放着我之前的一些颜色配置的代码。 2660 | \begin{Verbatim} 2661 | \usepackage{xcolor} 2662 | %=====在网上找的配黑色文字比较好的背景色======% 2663 | \definecolor{bgcolor-co}{RGB}{255,255,255} 2664 | \definecolor{bgcolor-dd}{RGB}{255,255,200} 2665 | \definecolor{bgcolor-tp}{RGB}{215,255,240} 2666 | \definecolor{bgcolor-bf}{RGB}{240,218,210} 2667 | \definecolor{defaultbgcolor-0}{RGB}{199,237,204} %for eye 2668 | 2669 | %\pagecolor{defaultbgcolor-0} 2670 | \end{Verbatim} 2671 | 2672 | 2673 | \subsection{定义新的颜色} 2674 | 上面颜色配置代码里有很多definecolor命令就是定义新的颜色的,然后在后面要用到颜色的地方使用你这里定义的新的颜色名字就可以了。第一个花括号就填着你定义的新颜色的名字。第二个花括号填着你要定义的颜色的模式,比如RGB,rgb,HTML,cmyk等。最后就是填着对应的模式的对应的数值。其中HTML模式不要\#号。 2675 | 2676 | \subsection{用软件查看颜色} 2677 | 你可以用手机照相,或者某个在某个网页某个文档上截图。然后用Gcolor2软件来捕捉某个点的颜色。 2678 | 2679 | \subsection{改变文章的背景颜色} 2680 | 上面代码最后的pagecolor命令就是设置整个文档背景颜色的。我试着在minipage模式下使用也会改变整个文章的背景颜色。 2681 | 2682 | 2683 | \subsection{改变字体的颜色} 2684 | 有两个命令,textcolor和color命令。 2685 | 2686 | \begin{Verbatim} 2687 | \textcolor{colorname}{some text} 2688 | 2689 | {\color{colorname} some text...} 2690 | \end{Verbatim} 2691 | 2692 | 2693 | \section{xcolor宏包简介} 2694 | xcolor宏包虽然是color宏包的扩展集,但对于我这个颜色知识盲来说多少有点不知所云,可能专业弄颜色的对那些颜色模式的增加还有颜色混合的表达扩展觉得很感动吧。如果你对颜色有更高级的需求,请详细阅读xcolor宏包文档,这里不赘述了。 2695 | 2696 | 就一般用户还是用definecolor命令吧,支持的模式有gray,rgb,RGB,HTML,cmyk。其中只要加载xcolor宏包就能使用的颜色名字如下: 2697 | 2698 | \begin{figure}[H] 2699 | \centering 2700 | \includegraphics[scale=1 , keepaspectratio]{xcolor.png} 2701 | \end{figure} 2702 | 2703 | 上面的图片所用的表格Tex代码用到了 \verb+cellcolor+ 这个命令,这在epub那边不能正常显示。这段代码贴出来吧,权做参考。 2704 | 2705 | \begin{Verbatim} 2706 | \begin{table}[H] 2707 | \centering 2708 | \begin{tabular}{@{}lp{50pt}lp{50pt}@{}} 2709 | \toprule 2710 | 颜色 & 效果 & 颜色 & 效果\\ \midrule 2711 | black & \cellcolor{black} & olive & \cellcolor{olive} \\ 2712 | blue & \cellcolor{blue} & orange & \cellcolor{orange}\\ 2713 | brown & \cellcolor{brown} & pink & \cellcolor{pink}\\ 2714 | cyan & \cellcolor{cyan} & purple & \cellcolor{purple}\\ 2715 | darkgray & \cellcolor{darkgray} &red & \cellcolor{red} \\ 2716 | gray & \cellcolor{gray} & teal & \cellcolor{teal}\\ 2717 | green & \cellcolor{green} & violet & \cellcolor{violet}\\ 2718 | lightgray & \cellcolor{lightgray} &white & \cellcolor{white} \\ 2719 | lime & \cellcolor{lime} & magenta & \cellcolor{magenta} \\ 2720 | yellow & \cellcolor{yellow}\\ \bottomrule 2721 | \end{tabular} 2722 | \caption{直接可以使用的颜色名字} 2723 | \label{tab:直接可以使用的颜色名字} 2724 | \end{table} 2725 | \end{Verbatim} 2726 | 2727 | 2728 | 如果你加载xcolor宏包时填上其他选项,比如svgnames等,就会有更多其他颜色的名字可以直接使用了。具体请参看\href{http://mirrors.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf}{xcolor官方文档}。 2729 | 2730 | 2731 | \subsection{单个颜色调百分比} 2732 | 虽然颜色混合我弄不大明白,不过单个颜色调百分比\footnote{不清楚和谁调?白色?}还是很有用的。比如gray灰色后面跟个!20,就表示20\%的灰。请看下面不同百分比的红色。 2733 | 2734 | \begin{Verbatim} 2735 | \begin{table}[H] 2736 | \centering 2737 | \begin{tabular}{@{}lp{50pt}lp{50pt}@{}} 2738 | \toprule 2739 | 颜色 & 效果 & 颜色 & 效果\\ \midrule 2740 | red & \cellcolor{red} & red!90 & \cellcolor{red!90} \\ 2741 | red!80 & \cellcolor{red!80} & red!70 & \cellcolor{red!70}\\ 2742 | red!60 & \cellcolor{red!60} & red!50 & \cellcolor{red!50}\\ 2743 | red!40 & \cellcolor{red!40} & red!30 & \cellcolor{red!30}\\ 2744 | red!20 & \cellcolor{red!20} &red!10 & \cellcolor{red!10} \\ 2745 | red!0 & \cellcolor{red!0}\\ \bottomrule 2746 | \end{tabular} 2747 | \label{tab:不同百分比的灰色} 2748 | \caption{不同百分比的灰色} 2749 | \end{table} 2750 | \end{Verbatim} 2751 | 2752 | 2753 | \begin{figure}[H] 2754 | \centering 2755 | \includegraphics[scale=1 , keepaspectratio]{xcolor_mix.png} 2756 | \end{figure} 2757 | 2758 | 值得一提的是xcolor宏包还支持一种表格颜色交替模式,看上去不错。请看带颜色的表格这一小节\ref{sec:带颜色的表格}。 2759 | 2760 | \chapter{表格环境} 2761 | 2762 | \section{表格横向一半的线条} 2763 | cmidline类似于原来的cline命令,简单来说就是你希望第几个到第几个格子画一条线。这个命令后面一样可以跟个描述粗细的可选项。请看下面的例子: 2764 | 2765 | \begin{Verbatim} 2766 | \begin{table}[H] 2767 | \centering 2768 | \begin{tabular}{@{}lll@{}} 2769 | \toprule 2770 | slices & \multicolumn{2}{l}{abs.error(slices)} \\ \cmidrule(l){2-3} 2771 | & avg. & max \\ \midrule 2772 | <5000 & 116 & 625 \\ 2773 | 5000-10000 & 209 & 1807 \\ 2774 | 10000-15000 & 297 & 2133 \\ 2775 | >15000 & 317 & 1609 \\ \bottomrule 2776 | \end{tabular} 2777 | \caption{cmidrule例子} 2778 | \label{tab:cmidrule例子} 2779 | \end{table} 2780 | \end{Verbatim} 2781 | 2782 | 显示效果如下: 2783 | 2784 | \begin{figure}[H] 2785 | \centering 2786 | \includegraphics[scale=1 , keepaspectratio]{cmidline.png} 2787 | \end{figure} 2788 | 2789 | 2790 | \section{表格放大或缩小} 2791 | 用scalebox和resizebox命令除了可以放大或者缩小图片之外,也可以用于放大或者缩小表格,这是值得注意的一件事,因为在排版的时候对表格的大小调整有的时候也是很重要的。 2792 | 2793 | 2794 | \begin{Verbatim} 2795 | \begin{table}[H] 2796 | \rowcolors{2}{}{lightgray!50} 2797 | \centering 2798 | \resizebox{\linewidth}{!}{ 2799 | \begin{tabular}{@{}ll@{}} 2800 | \rowcolor{lightgray!20} 2801 | 表格放大 & 说明 \\ 2802 | 1 & 2 \\ 2803 | 3 & 4 \\ 2804 | 5 & 6 2805 | \end{tabular} 2806 | } 2807 | \caption{表格放大} 2808 | \label{tab:表格放大} 2809 | \end{table} 2810 | \end{Verbatim} 2811 | 2812 | 显示效果如下: 2813 | 2814 | \begin{figure}[H] 2815 | \centering 2816 | \includegraphics[scale=1 , keepaspectratio]{scale_table.png} 2817 | \end{figure} 2818 | 2819 | 2820 | 2821 | \section[带颜色的表格]{带颜色的表格\footnote{本小节除了参看wikibook之外还参看了\href{http://texblog.org/tag/definecolor/}{这个网站}。}} 2822 | \label{sec:带颜色的表格} 2823 | xcolor宏包提供了一种颜色交替的表格模式,还挺好看的。好吧,我对颜色搭配不太擅长。首先需要在加载xcolor宏包时填上table可选项,即: 2824 | 2825 | \begin{Verbatim} 2826 | \usepackage[table]{xcolor} 2827 | \end{Verbatim} 2828 | 2829 | 2830 | \begin{Verbatim} 2831 | \begin{table}[H] 2832 | \rowcolors{2}{}{lightgray!50} 2833 | \centering 2834 | \resizebox{\linewidth}{!}{ 2835 | \begin{tabular}{@{}ll@{}} 2836 | \rowcolor{lightgray!20} 2837 | 实现本表步骤 & 备注 \\ 2838 | table环境下加上rowcolors命令 & 让整个表格交替显色 \\ 2839 | rowscolors第一个选项 & 决定颜色从那一行开始显示 \\ 2840 | rowscolors第二个选项 & 奇数列的颜色 \\ 2841 | 第三个选项 & 偶数列的颜色 \\ 2842 | 本表具体代码 & {\small \textbackslash rowcolors\{2\}\{\}\{lightgray!50\}} \\ 2843 | 第一行用rowcolor命令控制 & 在表头行上面 2844 | \end{tabular} 2845 | } 2846 | \caption{带颜色的表格} 2847 | \label{tab:带颜色的表格} 2848 | \end{table} 2849 | \end{Verbatim} 2850 | 2851 | \begin{figure}[H] 2852 | \centering 2853 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{color_table.png} 2854 | \end{figure} 2855 | 2856 | 2857 | \chapter{插入代码} 2858 | \section{tcolorbox宏包} 2859 | 这里用tcolorbox宏包的主要是想给代码块就是加上背景颜色。 2860 | 2861 | \begin{Verbatim} 2862 | %minted 2863 | \RequirePackage{minted}% 2864 | \RequirePackage[minted]{tcolorbox}% 2865 | \tcbuselibrary{breakable} 2866 | \newtcblisting{tcbminted}[2][]{listing engine=minted, 2867 | minted style=colorful,minted language=#2, 2868 | minted options={fontsize=\footnotesize}, 2869 | colback=blue!5!white,colframe=blue!75!black, 2870 | listing only,#1,breakable=true} 2871 | 2872 | \begin{tcbminted}{python} 2873 | class Hero(): 2874 | def addlevel(self): 2875 | self.level=self.level+1 2876 | self.hp=self.hp+self.addhp 2877 | 2878 | class Garen(Hero): 2879 | def __init__(self): 2880 | self.level=1 2881 | self.hp=455 2882 | self.addhp=96 2883 | self.skill=['不屈','致命打击','勇气','审判','德玛西亚正义'] 2884 | 2885 | garen001=Garen() 2886 | for i in range(6): 2887 | print('级别:',garen001.level,'生命值:' ,garen001.hp) 2888 | garen001.addlevel() 2889 | print('盖伦的技能有:',"".join([x + ' ' for x in garen001.skill])) 2890 | \end{tcbminted} 2891 | \end{Verbatim} 2892 | 2893 | \begin{figure}[H] 2894 | \centering 2895 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{tcolorbox.png} 2896 | \end{figure} 2897 | 2898 | 2899 | \chapter{数学环境} 2900 | \section{siunitx宏包} 2901 | 在排版物理书籍的时候常遇到一个问题,那就是比如10cm或者10米等等这样的数字加单位组合我们该如何排,特殊的符号或者一串公式甚至一大串公式当然用数学环境排这是没有疑问的,对于这样短小的数字和单位一般通用的做法是如何的呢? 2902 | 2903 | 一般的数字当然就是直接写,然后一般的单位也是直接写,比如10cm啊10米啊就是标准的做法。然后有些特殊的单位符号以及上标下标问题等如果用数学环境写,就会破坏文档这部分内容的谐调性,\emph{siunitx}宏包就是来解决这个问题的。 2904 | 2905 | 比如说\verb+\num{3d10}+的显示效果就是 \includegraphics[height=1.2\fontcharht\font`\B ]{siunitx_1.png},比如说\\ 2906 | \verb+100\si{\text{厘米}^3}+的显示效果就是 \includegraphics[height=1.2\fontcharht\font`\B ]{siunitx_2.png} 。 2907 | 2908 | siunitx宏包还有一个好处就是对于某些特殊的符号的输入也提供了支持,比如温度的度 \verb+\si{\degreeCelsius}+ 显示效果是 \includegraphics[height=1.2\fontcharht\font`\B ]{siunitx_3.png} 等等,此外还可以定制一些额外的符号: 2909 | \begin{Verbatim} 2910 | \sisetup{ 2911 | math-micro = \text{μ}, 2912 | text-micro = μ 2913 | } 2914 | \end{Verbatim} 2915 | 这样你就可以用\verb+\si{\micro m}+来显示\includegraphics[height=1.2\fontcharht\font`\B ]{siunitx_4.png}了。当然了这个宏包说白了就是对数学环境下某一些符号命令的text命令的一种包装吧,如果你能够直接输入那个符号就直接输入吧,这就是推荐的做法。 2916 | 2917 | 简单说来就是短小的数字或单位等还是不要麻烦数学环境了。更多的内容请参看siunitx官方文档,还可以参看\href{http://tex.stackexchange.com/questions/37168/when-to-use-math-mode}{这个网站}。 2918 | 2919 | 2920 | 2921 | \chapter{图片环境} 2922 | \section{导入pdf页面} 2923 | 这里要讲的是使用pdfpages宏包来实现多个pdf页面的导入。\\ 2924 | \verb+\usepackage[options]{pdfpages} +\\ 2925 | 默认是插入所有pdf页面,还有一些选项请参看文档。最常用的选项就是:\\ 2926 | \verb+pages={1,{},8-10}+\\ 2927 | 上面的意思是插入第一张页面,然后插入一个空页面,然后插入第八张到第十张。 2928 | 2929 | 2930 | \section{图片宽度最大宽度设置} 2931 | 在我学习html的时候发现html里面放置图片很方便设置max-width这个属性,大部分图片的宽度就不用操心了,心想latex可以实现这样的功能吗。就是图片宽度不超过你给定的max-width则图片是原宽度,如果超过了,则将其缩放到最大宽度,这样图片就不超过pdf的有效页面了。后来找到了 \href{http://tex.stackexchange.com/questions/86350/includegraphics-maximum-width}{这个网页} 给出的解决方案,很是不错 。 2932 | 2933 | 具体代码如下所示: 2934 | \begin{Verbatim} 2935 | \includegraphics[keepaspectratio,max width=0.95\linewidth]{images/lena.jpg} 2936 | \end{Verbatim} 2937 | 2938 | 你需要加载 \textbf{adjustbox} 宏包: 2939 | \begin{Verbatim} 2940 | \RequirePackage[export]{adjustbox}% 'export' is needed 2941 | \end{Verbatim} 2942 | 2943 | \chapter{插入摘要} 2944 | abstract环境就是摘要环境,不过book类不能使用摘要环境,只有article和report才有。命令格式如下: 2945 | \begin{Verbatim} 2946 | \begin{abstract} 2947 | 这是一段摘要文字。 2948 | \end{abstract} 2949 | \end{Verbatim} 2950 | 2951 | 2952 | \chapter{多栏环境} 2953 | \section{multicol宏包} 2954 | 多栏环境推荐使用\emph{multicol}宏包。\footnote{在beamer类下有一种看上去不错的多栏环境,就是使用的columns环境,不过只适用于beamer类的frame框架下。} 2955 | 这个宏包很厉害,支持两栏到十栏的环境。就作为通用的一般形式如下: 2956 | 2957 | 在这里每一栏的宽度表示为linewidth,这个可以用来控制放进去的图片宽度。 2958 | 这里用columnbreak命令手动调整栏的跳转。你也可以不用columnbreak命令,而让\TeX 自动计算栏的高度和分布等。不过似乎用columnbreak只能近似控制,并不是那种完全严格的跳转命令。 2959 | 2960 | 代码大致是这样的: 2961 | 2962 | \begin{Verbatim} 2963 | \begin{multicols}{2} 2964 | \setlength{\columnseprule}{0.4pt} 2965 | 如果你希望整个文档都分为两栏,那么在前面documentclass命令可选项里面... 2966 | 2967 | 还有一个长度量columnsep表示栏之间的间距宽度... 2968 | \end{multicols} 2969 | \end{Verbatim} 2970 | 2971 | 2972 | \begin{figure}[H] 2973 | \centering 2974 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{multicolumn.png} 2975 | \end{figure} 2976 | 2977 | 2978 | 2979 | 2980 | 2981 | 2982 | \chapter{如何显示更多的特殊符号} 2983 | 本小节内容建议读者从理解Tex字体的原理来学习,但真的不推荐使用。 2984 | 2985 | 现在让我们将思路先理清一下。首先是Unicode码,这个只是一个理论上的编码规则,具体的实现是字体。但是每一个字体都只专注于某一个领域,并没有把Unicode所有的码都画出字形来,那么系统是如何显示字体的呢?系统是安装了很多字体,如果一个字体并不包含它要显示的Unicode,它就搜索打开下一个字体文件,找相关的Unicode的字形。只有从字体文件中具体找了这个Unicode的字形,才有办法将其显示出来。 2986 | \footnote{主要参考了\href{http://tex.stackexchange.com/questions/41130/getting-xelatex-to-display-accents-and-characters-not-included-with-the-font}{这个网站}} 2987 | 2988 | 现在我希望显示Ubuntu的那个图标,那个图标实际上也是一个字体。具体配置代码如下: 2989 | 2990 | \begin{Verbatim} 2991 | \newfontfamily{\ubuntu}[Scale=2]{Ubuntu} 2992 | \usepackage{newunicodechar} 2993 | \newunicodechar{}{{\ubuntu{}}} 2994 | \end{Verbatim} 2995 | 2996 | 主要是利用的newunicodechar宏包。这个宏包就只有一个命令,这个命令就是这个宏包的名字。其实我们能够猜到,这个命令的作用就是将这个字符变成类似\TeX 命令的东西,然后替换为后面的那一串,而后面的那一串单独提出来也是能够正常显示的。具体效果就是这个Ubuntu图标你直接在Tex文档上复制粘贴到哪里了,就能够显示。甚至你的操作系统都没办法显示出来只是一段空白。 2997 | 2998 | \begin{figure}[H] 2999 | \centering 3000 | \includegraphics[scale=1 , keepaspectratio]{ubuntu_logo_font.png} 3001 | \end{figure} 3002 | 3003 | 3004 | \chapter{旁注} 3005 | \LaTeX 自带的有marginpar命令就是插入旁注的(你需要把页面布局的旁注部分设置好。)我也接触过另外一个宏包的marginnote命令,虽然多了一个可选项可以调整旁注竖向位移,但是带来的麻烦更多,有时候页尾的旁注会向下越界,如果我想写了一个旁注,又在下面继续写一个旁注命令也会出现重叠出错。而marginpar就没有这样的问题。写了一个marginpar,后面可以继续再开一条marginpar命令。至于竖向位移的问题,使用vspace命令调整即可。 3006 | 3007 | 下面是我新建的一个rightnote命令,以供参考。 3008 | \begin{Verbatim} 3009 | \newcommand{\rightnote}[1]{\marginpar{ 3010 | \fontsize{10pt}{12pt}\selectfont #1}} 3011 | \end{Verbatim} 3012 | 3013 | 在maginpar命令里面进行各种\LaTeX 命令都是可以的,比如改变字体大小,字体颜色,插入图片等等。 3014 | 3015 | 3016 | 3017 | 3018 | 3019 | \part{tex高级篇} 3020 | 本部分关注于tex最底层的一些概念和原理,有些知识点了解之后对读者如何定制tex原有的命令和功能有所帮助,有些能够加深读者对tex底层如何工作的理解。 3021 | 3022 | 更深入的学习推荐查阅\href{http://www.tug.org/utilities/plain/cseq.html}{这个网站} 和阅读高德纳写的 The TexBook。 3023 | 3024 | 3025 | \chapter{长度量} 3026 | \section{单位} 3027 | \LaTeX{}中常见的长度单位如下表所示: 3028 | \begin{table}[H] 3029 | \centering 3030 | \caption{\LaTeX{}中的常见长度单位} 3031 | \label{tab:LaTeX中的常见长度单位} 3032 | \medskip 3033 | \begin{tabular}{@{}lll@{}} 3034 | \toprule 3035 | 单位 & 说明 & 换算法则 \\ \midrule 3036 | pt & &\\ 3037 | mm & 一毫米 & 1mm=2.84pt \\ 3038 | cm & 一厘米 & 1cm=28.4pt \\ 3039 | in & 一英寸 & 1in=72.27pt \\ 3040 | ex & (相对长度)大约相当于当时字体的x高度 & \\ 3041 | em & (相对长度)大约相当于当时字体的M宽度 & \\ \bottomrule 3042 | \end{tabular} 3043 | \end{table} 3044 | 3045 | 3046 | \section{默认的长度量} 3047 | \begin{itemize} 3048 | \item \textbf{\textbackslash evensidemargin ~ \textbackslash linewidth ~ \textbackslash oddsidemargin ~ \textbackslash paperwidth ~ \textbackslash paperheight ~ \textbackslash textheight ~ \textbackslash textwidth ~ \textbackslash topmargin }:这些长度量都和页面布局有关,很多都在前面页面布局那一节里面说了,这里就不赘述了。 3049 | \item \textbf{\textbackslash baselineskip ~ \textbackslash baselinestretch ~\\ \textbackslash baselineskip ~ \textbackslash parindent ~ \textbackslash parskip }:这些长度量和段落格式有关,大多都在前面段落一节说了,这里也不赘述了。 3050 | \item \textbf{\textbackslash columnsep ~ \textbackslash columnwidth ~ \textbackslash tabcolsep ~ \textbackslash unitlength}:这几个长度量和特殊的环境有关,比如columnsep控制多栏环境之间的宽度,columnwidth控制栏的宽度,tabcolsep控制tabular环境一列一列之间的间距,unitlength控制picture环境下的unit的长度(还不太清楚)。 3051 | \end{itemize} 3052 | 3053 | 3054 | \section{定义自己的长度量} 3055 | 要新建一个自己的长度量使用newlength命令即可:\\ 3056 | \verb+\newlength{\lengthname}+ 3057 | 3058 | \section{修改长度量} 3059 | 用setlength命令直接设值某个长度量的值为多少。\\ 3060 | \verb+\setlength{\lengthname}{20pt}+ 3061 | 3062 | 此外还可以使用addtolength命令来给某个长度值加上一个数值。\\ 3063 | \verb+\addtolength{\lengthname}{20pt}+ 3064 | 3065 | \section{使用长度量} 3066 | 长度量一般在该使用的地方可以直接使用,其中伸缩量可以跟一个plus量和一个minus量。此外长度量还支持前面加个实数表示相乘多少的形式。\\ 3067 | \verb+0.7\lengthname+ 3068 | 3069 | \subsection{显示长度量的值} 3070 | 要在pdf文档中显示某个长度量的值使用\textbackslash the命令即可:\\ 3071 | \verb+\the\lengthname+ 3072 | 3073 | \section{calc宏包介绍} 3074 | 前面提及的setlength,addtolength命令只能接受最简单的长度量,在引入calc宏包之后可以进行一般的中缀数学表达式的运算。更多内容请读者自己翻看\href{http://mirrors.ctan.org/macros/latex/required/tools/calc.pdf}{官方手册}。 3075 | 3076 | 3077 | 3078 | 3079 | \chapter{计数器} 3080 | 计数器(counter)之前也接触过一些了,现在基于wikibook和\href{http://texblog.org/2007/07/25/counters-in-latex/}{这篇博文}做一些整理工作。 3081 | 3082 | 3083 | \section{latex默认的计数器} 3084 | \begin{itemize} 3085 | \item \textbf{part chapter section subsection subsubsection paragraph \linebreak subparagraph} 这些计数器我们在前面的章节编号形式修改那一小节中有所接触,具体请参看章节编号形式修改这一小节:\ref{sec:章节编号形式修改}。 3086 | \item \textbf{equation figure table} 这三个是浮动体环境的计数器,其中figure我们在前面的图片标题的修改那一小节有所接触,具体请参看图片标题的修改这一小节:\ref{sec:图片标签的修改}。 3087 | \item \textbf{page footnote mpfootnote} page看得出来是页面的计数器,还没怎么接触。footnote是脚注的计数器,这个在DIY脚注的时候会接触到,mpfootnote是minipage下的脚注的计数器,这个知识点参看的\href{http://tex.stackexchange.com/questions/18499/how-to-change-symbol-for-footnote-in-minipage}{这个网站}。 3088 | \item 此外enumerate环境里面还有专门的计数器:\textbf{enumi enumii enumiii enumiv}。enumi记录的是当前enumerate环境第一级的item出现的次数,后面的依次是第二级第三级等等,不怎么常用。具体请参看enumerate环境标签的修改这一小节:\ref{sec:enumerate环境标签的修改} 3089 | \end{itemize} 3090 | 3091 | 3092 | 3093 | \section{使用计数器} 3094 | 计数器并不可以直接使用,需要使用以下命令来获得某个特殊形式的值。 3095 | \begin{description} 3096 | \item[value] 将计数器转化为数值方便后面的计算,不能作为字符直接显示。 3097 | \item[arabic] 将计数器转化为1 2 3...的形式,可以直接显示。 3098 | \item[alph] 将计数器转化为a b c...的形式,可以直接显示。 3099 | \item[Alph] 将计数器转化为A B C...的形式,可以直接显示。 3100 | \item[roman] 将计数器转化为ⅰ ⅱ ⅲ... 的形式,可以直接显示。 3101 | \item[Roman] 将计数器转化为Ⅰ Ⅱ Ⅲ...的形式,可以直接显示。 3102 | \item[fnsymbol] 将计数器转化为一系列的特殊符号。 3103 | \end{description} 3104 | 3105 | \section{计数器变成带圈的数字系列} 3106 | 我想新建一个命令,这个命令可以把计数器转化为①②③...这样的形式,可以直接显示。可以看得出来这个命令会很实用的。 3107 | 3108 | \subsection{用tikz画的方法} 3109 | \begin{Verbatim} 3110 | \newcommand*\circled[1]{% 3111 | \tikz[baseline=(char.base)]\node 3112 | [shape=circle,draw,inner sep=1pt,minimum size=8pt] (char) {#1};} 3113 | \newcommand*\circledarabic[1]{\circled{\arabic{#1}}} 3114 | \end{Verbatim} 3115 | 3116 | 上面这段代码参考了\href{http://tex.stackexchange.com/questions/133264/circled-footnote-symbols-with-pifont-showing-arrows-instead-of-circled-numbers}{这个网站}。看得出来代码大体过程就是利用tikz宏包画出那个符号出来。 3117 | 3118 | 这个方法的好处是自由度比较高,根据circled命令,类似的可以定义circledalph——圈圈里面带个字母等。这个方法还有一个好处,虽然①②这样的符号Unicode里面有,但是字体没有,如前面所述,还是需要写上一连串的代码,多少有点费事,而且到后面数字大了总会没有这个字体符号了,就会出错,而这个方法可以避免这些麻烦。推荐使用这个方法。 3119 | 3120 | 3121 | \section{定义自己的计数器} 3122 | 用newcounter命令来定义自己新的计数器。\\ 3123 | \verb+\newcounter{countername}+ 3124 | 3125 | \section{修改计数器的值} 3126 | 系统默认的计数器都是默认设置初始值为0,如果你需要使用这个计数器,首先加一,然后使用这个计数器。 3127 | \subsection{计数器设值} 3128 | 直接将计数器设为某个值用setcounter命令。\\ 3129 | \verb+\setcounter{countername}{number}+ 3130 | \subsection{计数器加一} 3131 | 将计数器数值加一使用stepcounter命令。\\ 3132 | \verb+\stepcounter{countername}+ 3133 | 3134 | \subsection{计数器加多少} 3135 | 将计数器加上一个数值使用addtocounter命令。\\ 3136 | \verb+\addtocounter{countername}{number}+ 3137 | 3138 | \section{计数器和其他计数器绑定} 3139 | 在使用newcounter命令定义新的计数器的时候可以后面跟个可选项,可选项里填著另外一个计数器的名字,每当这个计数器加一的时候你定义的新的计数器就会归为零。具体格式如下: 3140 | \begin{Verbatim} 3141 | \newcounter{mycounter}[chapter] 3142 | \end{Verbatim} 3143 | 这样每当chapter加一也就是到了新的一章,你定义的mycounter将会重新归零。 3144 | 3145 | 3146 | 3147 | 3148 | 3149 | \chapter{新的命令或环境} 3150 | \section{新的命令} 3151 | 新建命令一般就用newcommand命令\\ 3152 | \verb+\newcommand{name}[num]{definition}+\\ 3153 | 用法都差不多,第一个必填选项是新建命令的名字,一般前面都加一个\textbackslash 符号。第二个可选选项是新建的这个命令接受的参数,比如你填一个2,那么表示这个命令接受两个参数,在后面definition中引用的时候\#{}1表示第一个参数,\#{}2表示第二个参数。 3154 | 3155 | 然后还有这种形式:\\ 3156 | \verb+\newcommand{name}[num][default]{definition}+\\ 3157 | 多的那个default参数是可选参数的默认值,在definition那边对应的就是 \#{}1。这个可选参数如果不填那么默认值为 \verb+def+ ,然后后面利用这个新的命令可以如下填上那个可选参数。 3158 | 3159 | \begin{minted}{tex} 3160 | \newcommand\GoodBye[1][\bfseries]{{#1 Good Bye}} 3161 | 3162 | \GoodBye 3163 | \GoodBye[\color{red}] 3164 | \end{minted} 3165 | 3166 | 3167 | 3168 | 下面是具体运行效果: 3169 | 3170 | \begin{figure}[H] 3171 | \centering 3172 | \includegraphics[scale=1 , keepaspectratio]{self_define_command_1.png} 3173 | \end{figure} 3174 | 3175 | \LaTeX 的newcommand命令是由原\TeX 的def命令(还有edef gdef xdef 这里先不管。)而来的。作用原理有点类似于替换展开的功能。比如:\\ 3176 | \verb+\newcommand{\test}{this is a test line}+\\ 3177 | 你定义了这个test命令,然后后面你输入\textbackslash test,系统遇到\textbackslash test之后就会进行替换操作,就成了后面的this is a test line了。理论上只是简单的文本替换,后面可是跟上随意的命令参数或者环境。不过这只是理论上,实际编写宏包命令的时候会遇到很多复杂的问题,主要是expand展开的控制。 3178 | 3179 | 3180 | 3181 | 3182 | 3183 | \subsection{自定义命令样例} 3184 | 下面是来自ulem的reduline的原实现代码: 3185 | 3186 | \begin{Verbatim} 3187 | \newcommand\reduline{\bgroup\markoverwith 3188 | {\textcolor{red}{\rule[-0.5ex]{1em}{0.4pt}}} 3189 | \ULon} 3190 | \end{Verbatim} 3191 | 3192 | \subsection{renewcommand命令} 3193 | renewcommand用法类似newcommand命令,用于重新定义某个已经存在的命令。 3194 | 3195 | 3196 | \subsection{providecommand命令} 3197 | providecommand命令用法类似newcommand命令,区别就是如果该命令已经存在,那么不会重新定义。 3198 | 3199 | 3200 | \section{新的环境} 3201 | \label{sec:新的环境} 3202 | 新建环境命令格式如下:\\ 3203 | \verb+\newenvironment{name}[num]{before}{after}+\\ 3204 | 和newcommand命令其他用法都差不多,区别就在于后面有两个宏替换。这里值得一提的是原\TeX 并没有新建环境这个命令,而是\LaTeX 新加进去的。 3205 | 3206 | 我们假设我们要新建env这个环境,那么\LaTeX 的工作流程是,创建了两个命令,一个是\verb+\begin{env}+命令;一个是\verb+\endenv+命令。所以简单的来看newenvironment命令就是把它看作开辟了一个group(原\TeX 里面的概念),然后首先执行了before中的命令,然后是环境中的内容,然后是after中的命令,然后退出环境。 3207 | 3208 | 这里只是说明一下newenvironment命令的工作原理,具体我们新建环境还是用\LaTeX 的风格,即用newenironment命令,只有在不得已的情况下(通常很复杂的情况)才考虑用\TeX 里面的group概念,那个时候估计是要使用catcode命令。 3209 | 3210 | 3211 | 3212 | \subsection{notecard环境} 3213 | 这个环境编写主要参考\href{http://tex.stackexchange.com/questions/127612/color-text-and-bg-of-verbatim-without-affecting-fancyvrb-line-numbers}{这个网站}。 3214 | 3215 | 有一类信息,这类信息和正文关系不太大,但是又很重要适合放在正文中而不是尾注或者脚注中。这类信息需要放在文档右边好不引起人们的注意或者好引起人们的注意。文档中的异常元素通常都有这个效果,在于读者的选择。 3216 | 3217 | notecard环境,一种卡片式记忆环境,长高推荐按照黄金比例来。推荐的颜色有:black olive blue orange brown pink cyan purple darkgray red gray teal green violet lightgray white lime magenta yellow 建议都调淡30。不过推荐一个文档内部一种类型只使用一种颜色,颜色太杂也是不好的。 3218 | 3219 | 具体实现代码如下: 3220 | \begin{Verbatim} 3221 | \newsavebox{\tempbox} 3222 | \newenvironment{notecard}[2][white] 3223 | {\noindent\ignorespaces% 3224 | \setlength{\fboxsep}{10pt} 3225 | \newcommand{\tempcolor}{#1} 3226 | \begin{lrbox}{\tempbox}% 3227 | \begin{minipage}{#2} 3228 | \setlength{\parindent}{0pt} 3229 | \setlength{\parskip}{1.618ex} %段落間距 3230 | } 3231 | { 3232 | \ignorespacesafterend% 3233 | \end{minipage}% 3234 | \end{lrbox}% 3235 | \colorbox{\tempcolor}{\usebox{\tempbox}}} 3236 | \end{Verbatim} 3237 | 3238 | 这个notecard代码环境有点小复杂,主要涉及到\LaTeX 盒子相关高级知识,这里先跳过去,后面会提及再慢慢讲。 3239 | 3240 | 3241 | 3242 | \begin{Verbatim} 3243 | \begin{flushright} 3244 | \begin{notecard}[blue!30]{14em} 3245 | 不懂Unix的人注定最终还要重复发明一个蹩脚的Unix。 3246 | 3247 | Usenet 签名,1987年11月 3248 | 3249 | {\hfill —Henry Spencer} 3250 | \end{notecard} 3251 | \end{flushright} 3252 | \end{Verbatim} 3253 | 3254 | 下面是演示效果: 3255 | 3256 | \begin{figure}[H] 3257 | \centering 3258 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{notecard.png} 3259 | \end{figure} 3260 | 3261 | 3262 | \chapter{盒子和glue} 3263 | \label{sec:盒子和glue} 3264 | \begin{flushright} 3265 | \begin{framed} 3266 | 这里参考了Knuth的The Texbook,但是我并没有将其写入参考文献,因为只是觉得关于box和glue的概念最好参考原初定义,但是并不推荐读者阅读这本书,现在已经是\LaTeX 时代了,不推荐读者使用原始的\TeX 命令,一是不太实用,二是兼容性可能不太好。除非你是宏包编写者,但就作为一般的使用者真的没有必要接触那些原始命令了。还参考了\cite{boxes} 3267 | \end{framed} 3268 | \end{flushright} 3269 | 3270 | 在这里box翻译为盒子没什么问题,就是这个glue翻译为胶水或者橡皮都让我不太满意。在后面我都使用的术语是距离或者间距或者干脆用英文glue。从某种意义上讲glue的直译确实应该译为胶或者胶水,不过觉得距离这个词汇更能够让人们有感觉些:\TeX 排版就是不同的盒子编写和彼此之间距离的设置问题。 3271 | 3272 | \section{基本知识} 3273 | 最小的盒子就是基于Unicode的字符,这些字符然后组成更大的盒子──单词,然后单词组成更大的盒子──行等等。行是一个盒子,段落也是一个盒子,图片是一个盒子,表格也是一个盒子。而这些盒子按照Knuth的描述都是用glue胶水粘合起来的,或者我们称之为这些盒子之间都存在着空间胶合层。下面就是一个盒子的详细参数: 3274 | 3275 | \begin{figure}[H] 3276 | \centering 3277 | \includegraphics[width=0.8\linewidth ,totalheight=0.95\textheight , keepaspectratio]{box-parameters.png} 3278 | \caption{box参数} 3279 | \label{fig:box参数} 3280 | \end{figure} 3281 | 3282 | 3283 | 盒子就是这么一个长方形的区域,如上图所示,它有参数:height,width,depth。baseline和reference point在后面讲的hbox和vbox中会用到。在\TeX 看来,从字体而来的Unicode 字符就是一个最简单的盒子。字体的设计者已经决定了这个字符的高度,宽度和深度以及它在这个盒子里面看起来如何。\TeX 就是用这些维度将盒子黏合到一起,并最终决定所有字符的reference point 参考点在页面上的位置。 3284 | 3285 | \TeX 的盒子如果全部涂上颜色,一般是黑色,那么就成了一个黑盒子。这样的黑盒子还有一个名字叫做rule box。也就是线条。这个在后面会谈论到的。 3286 | 3287 | 不管是字符盒子还是黑盒子,他们要某是水平排列要某是垂直排列。水平排列要做的就是让这些盒子的参考点在一条水平线上。类似的垂直排列要做的就是让这些盒子的参考点在一条垂直线上。 3288 | 3289 | 好吧,介绍两个\TeX 命令:hbox和vbox。hbox命令就是让所有的盒子在一条水平线上,而vbox命令就是把一些hbox命令垂直排列,比如下面的代码: 3290 | 3291 | \begin{Verbatim} 3292 | \vbox{\hbox{恭}\hbox{喜} \hbox{发}\hbox{财}} 3293 | \end{Verbatim} 3294 | 3295 | 3296 | \begin{figure}[H] 3297 | \centering 3298 | \includegraphics[scale=1 , keepaspectratio]{vbox_show.png} 3299 | \end{figure} 3300 | 3301 | glue也就是各个盒子之间的间距。下图是glue的具体图示: 3302 | 3303 | \begin{figure}[H] 3304 | \centering 3305 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{glue.png} 3306 | \caption{glue说明} 3307 | \label{fig:glue说明} 3308 | \end{figure} 3309 | 3310 | 3311 | 前面说到盒子的reference point水平排列,然后他们之间还有叫做glue的间距。间距有三个属性:正常间距量(space),拉伸量(stretch),缩减量(shrink)。比如这个图片中第一个glue的正常间距是9个单位,拉伸量为3个单位,缩减量为1个单位。而总的情况是正常间距是5(box1)+9+6+9+3+12\- +8=52个单位。现在假设一行宽58个单位,\TeX 就要调整使得这一行盒子的宽度刚好等于58个单位,于是还需要增加6个单位的宽度,而这6个单位的宽度\footnote{为了简单起见这里不考虑缩减量,具体缩减量如何计算我也不大清楚。}需要从这一行所有glue里的拉伸量中找出来。于是总的拉伸量加法是3+6+0=9。也就是6个单位的宽度要分成9等分再分配给他们,即第一个glue的拉伸量是$3\times\frac { 6 }{ 9 } $。这样第一个间距的总长度就是$9+3\times\frac { 6 }{ 9 } =11$。 3312 | 3313 | 经过计算所有的glue间距都确定下来了,那么整个页面布局就确定了。我在这里就戛然而止了,毕竟这里只是对box和glue的基本概念的阐明。 3314 | 3315 | 3316 | \section{盒子命令介绍} 3317 | \href{http://tex.stackexchange.com/questions/83930/what-are-the-different-kinds-of-boxes-in-latex}{参考了这个网站} 3318 | 3319 | \subsection{makebox} 3320 | \verb+\makebox[width][allignment]{some text}+\\ 3321 | 还有一个mbox,不过makebox命令更加全面,推荐使用。makebox就是制造一个水平的盒子,注意这个box里面的文本是不能换行的,也就是一行之内的盒子。第一个可选项width指这个盒子的长度,第二个可选项allignment是里面文本的对齐方式,有【l c r s】几个选项,\emph{l}表示左对齐;\emph{c}表示居中;\emph{r}表示right;\emph{s}表示两端对齐。 3322 | 3323 | 3324 | 3325 | \subsection{raisebox} 3326 | raisebox命令一般的用法就是:\\ 3327 | \verb+\raisebox{高度}{内容}+\\ 3328 | 表示把某个内容放进一个盒子里然后抬高多少高度,高度值可以是负值则是降低。 3329 | 3330 | \subsection{resizebox} 3331 | \href{http://tex.stackexchange.com/questions/13460/scalebox-knowing-how-much-it-scales}{参照了这个网站} 3332 | 3333 | resizebox命令是由graphics宏包提供的,一般都加载了吧。比如tikz绘图的时候如果你只是简单scale那么node内容会出现很大的偏差。这个时候如果你使用scalebox命令则可以将整个图片进行大小变换。 3334 | 3335 | 用法如下:\\ 3336 | \verb+\resizebox{宽度}{高度}{内容} +\\ 3337 | \verb+\resizebox{\linewidth}{!}{内容}+\\ 3338 | \verb+\scalebox{2}{测试文字}+ 3339 | 3340 | 第二个的用法是将这个图片放大到文本宽度,高度填“!”符号的意思是随之而变化。 3341 | 3342 | 3343 | 3344 | \subsection{parbox和minipage} 3345 | parbox用法:\\ 3346 | \verb+\parbox[pos][height][contentpos]{width}{text}+ 3347 | 3348 | minipage用法: 3349 | \begin{Verbatim} 3350 | \begin{minipage}[pos][height][contentpos]{width} 3351 | text 3352 | \end{minipage} 3353 | \end{Verbatim} 3354 | 3355 | 他们的参数都类似,具体说明如下: 3356 | \begin{description} 3357 | \item[pos] \textbf{c}enter,\textbf{t}op和\textbf{b}ottom,说是控制盒子相对周围文本内容的位置。 3358 | \item[height] 盒子高度 3359 | \item[contentpos] \textbf{c}enter,\textbf{b}ottom,\textbf{t}op,\textbf{s}pread。文本分布,居中,底部,顶部或两端对齐。 3360 | \end{description} 3361 | 3362 | 3363 | \section{带颜色或者线框的盒子} 3364 | \subsection{framebox} 3365 | framebox和makebox命令类似,除了加上了一个线框。\\ 3366 | \verb+\setlength{\fboxsep}{10pt}+\\ 3367 | \verb+\setlength{\fboxrule}{5pt}+\\ 3368 | 如上面描述的这里有两个长度量,fboxsep控制线框和文字之间的距离,fboxrule控制线框的宽度。值得一提的是framebox,fbox 或者fcolorbox命令的线框的这两个参数都是类似上面的代码控制的。 3369 | 3370 | 3371 | \subsection{colorbox} 3372 | colorbox,带颜色的盒子。第一个参数是背景颜色,第二个参数是盒子里面的内容。 3373 | 3374 | \begin{Verbatim} 3375 | \colorbox{yellow!50}{this is a test line.} 3376 | \end{Verbatim} 3377 | 3378 | \begin{figure}[H] 3379 | \centering 3380 | \includegraphics[scale=1 , keepaspectratio]{colorbox.png} 3381 | \end{figure} 3382 | 3383 | 3384 | \subsection{fcolorbox} 3385 | fcolorbox和colorbox的区别就是外面加了一个边框,然后第一个参数是边框的颜色,第二个参数是背景颜色,第三个参数是盒子里面的内容。 3386 | 3387 | \begin{Verbatim} 3388 | \fcolorbox{red!50}{yellow!30}{this is a test line.} 3389 | \end{Verbatim} 3390 | 3391 | \begin{figure}[H] 3392 | \centering 3393 | \includegraphics[scale=1 , keepaspectratio]{fcolorbox.png} 3394 | \end{figure} 3395 | 3396 | 3397 | 3398 | \chapter{线条} 3399 | \verb+\rule[depth]{width}{height}+ 3400 | 这三个选项都要填长度量,第一个长度量是线条竖向偏移量,第二个长度量是线条横向长度,第三个长度量是线条竖向宽度。 3401 | 3402 | \chapter{编写自己的宏包} 3403 | 宏包基本的骨架如下: 3404 | 3405 | \begin{Verbatim} 3406 | % mybook.sty 3407 | \NeedsTeXFormat{LaTeX2e} 3408 | \ProvidesPackage{mybook}[2025/04/29 A simple book config package] 3409 | \makeatletter 3410 | 3411 | 3412 | \makeatother 3413 | \endinput 3414 | \end{Verbatim} 3415 | 3416 | 宏包中某些内部命令会带上 \verb+@+ 符号,这些命令或者变量外面是不可以使用的,一般宏包里面还是希望能够直接使用,所以如上 \verb+\makeatletter ... \makeatother+ 对整个宏包内容进行了封装。 3417 | 3418 | \section{条件语句} 3419 | 一个简单的条件语句如下: 3420 | 3421 | \begin{Verbatim} 3422 | \makeatletter 3423 | % 定义一个布尔型开关 3424 | \newif\if@code 3425 | 3426 | % 设置开关为 false 3427 | \@codefalse 3428 | 3429 | % 进行条件判断 3430 | \if@code 3431 | 代码开关为真。 3432 | \else 3433 | 代码开关为假。 3434 | \fi 3435 | \makeatother 3436 | \end{Verbatim} 3437 | 3438 | \section{RequirePackage命令} 3439 | 编写宏包加载其他宏包推荐使用 \verb+RequirePackage+ 命令,\verb+usepackage+ 则推荐外面文档使用。 3440 | 3441 | \section{PassOptionsToPackage命令} 3442 | 编写宏包的时候,推荐用PassOptionsToPackage命令提前将一些宏包的选项统一设置好,这些选项会在后面加载对应宏包的时候传递进去。这在处理选项冲突时有用。 3443 | 3444 | \section{给你的宏包定义选项} 3445 | 一个简单的例子如下: 3446 | \begin{Verbatim} 3447 | % mypackage.sty 3448 | \NeedsTeXFormat{LaTeX2e} 3449 | \ProvidesPackage{mypackage}[2025/04/29 A sample package with options] 3450 | 3451 | % 定义选项 option1 3452 | \DeclareOption{option1}{ 3453 | % 当使用 option1 选项时执行的代码 3454 | \newcommand{\myoption}{You have chosen option 1.} 3455 | } 3456 | 3457 | % 处理未定义的选项 3458 | \DeclareOption*{% 3459 | \PackageWarning{mypackage}{Unknown option `\CurrentOption'}% 3460 | } 3461 | 3462 | % 处理所有选项 3463 | \ProcessOptions\relax 3464 | 3465 | \endinput 3466 | \end{Verbatim} 3467 | 3468 | 需要注意的是,实际宏包编写中,\verb+\ProcessOptions\relax+ 这句要在你的宏包内容主题的前面,除了 \verb+PassOptionsToPackage+ 和一些简单的变量设置外,不能加载其他宏包。所以选项上面实践中只能把一些布尔值设置好,方便后面采取不同的行为。 3469 | 3470 | 3471 | \section{TeX中执行系统的命令} 3472 | \href{http://tex.stackexchange.com/questions/20444/what-are-immediate-write18-and-how-does-one-use-them}{参考了这个网站} 3473 | 3474 | \TeX 的write18命令将一连串文本命令送入shell中执行,一般语句的格式如下(immediate命令是立即执行的意思。这里表示将命令立即送入shell现在就执行。):\\ 3475 | \verb+\immediate\write18{your command put it here}+ 3476 | 3477 | 要成功运行这个命令记得你的编译选项上还需要加上:\\ 3478 | \verb+--enable-write18+ 3479 | 3480 | 比如目前我的texmaker的编译命令如下: 3481 | \begin{Verbatim} 3482 | xelatex -synctex=1 -interaction=nonstopmode 3483 | --enable-write18 %.tex 3484 | \end{Verbatim} 3485 | 3486 | \appendix 3487 | \part{附录} 3488 | 3489 | 3490 | \chapter{windows下作业} 3491 | windows安装其实还更简单一些,就是搜索 \emph{texlive} 然后安装之即可。 3492 | 3493 | 推荐把texmaker也下载下来安装好,然后其编译命令本文已有所叙述,大体是: 3494 | \begin{Verbatim} 3495 | xelatex -synctex=1 -interaction=nonstopmode --enable-write18 %.tex 3496 | \end{Verbatim} 3497 | 3498 | 其中minted宏包需要你安装好python环境,然后用pip安装pygments。然后下面是一些重要的注意事项: 3499 | 3500 | \section{windows下作业请注意} 3501 | \begin{itemize} 3502 | \item 图片名字,本tex文件名字和重要的文件夹名字都必须使用拼音或英文,不能带中文字符! 3503 | \item 其他的都还好吧。 3504 | \end{itemize} 3505 | 3506 | 3507 | \section{windows下安装字体} 3508 | 双击打开字体文件,右边就有个安装字体按钮。 3509 | 3510 | 3511 | \chapter{ubuntu下作业} 3512 | \section{配置\LaTeX 编写环境} 3513 | \label{sec-8} 3514 | \begin{enumerate} 3515 | \item sudo apt-get install texlive (下载安装有名的texlive) 3516 | \item sudo apt-get install texlive-full (下载安装texlive的各个包) 3517 | \item 在ubuntu软件中心中下载安装texmaker软件。 3518 | \item 在texmaker的选项和配置texmaker里面 (现在texmaker已经加入XeLaTeX 编译命令。),设置快速构建,点上用户自定义那一栏,然后输入如下命令: 3519 | \end{enumerate} 3520 | 3521 | \begin{Verbatim} 3522 | xelatex -interaction=nonstopmode \%.tex| 3523 | \end{Verbatim} 3524 | 3525 | 这是使用xelatex来对目标tex文件进行编译,而不是传统的latex或者pdflatex方式,之所以这样是因为多方对比之后,觉得其在字体处理方面是未来的趋势。 3526 | 3527 | 3528 | \section{ubuntu安装字体} 3529 | \subsection{找字体文件} 3530 | 如果你装了windows系统,那么你可以到windows下copy这些字体文件。比如windows常用的宋体,times new roman等,在C盘的windows的fonts文件夹里面。本文用的就是adobe中文系列:adobe 宋体 std, adobe 黑体 std , adobe 楷体 std 。 3531 | 3532 | 或者去网络上下载。 3533 | 3534 | \subsection{放置字体文件} 3535 | 3536 | 推荐都放在ubuntu的主目录的 \verb+.fonts+ 文件夹里面(这是一个隐藏目录),如果没有请新建一个。这是通常默认用户新加字体放置的目录。 3537 | 3538 | \subsection{安装字体} 3539 | 3540 | 运行命令: 3541 | \begin{minted}{bash} 3542 | fc-cache -f -v 3543 | \end{minted} 3544 | 3545 | 3546 | 字体就安装好了,如果你要看现在你的系统上有那些可用的中文字体,在终端运行命令: 3547 | \begin{minted}{bash} 3548 | fc-list :lang=zh | sort >ziti.txt 3549 | \end{minted} 3550 | 3551 | 3552 | \verb+|+ 表示linux命令中的通道,第一个命令的输出信息流会流向sort命令,排序之后重定向到ziti.txt文件里面。然后终端的数据就保存在这个文件里面了。 3553 | 3554 | 打开ziti.txt,里面就是你的可用中文字体的信息,比如: 3555 | \begin{Verbatim} 3556 | /home/wanze/.fonts/simsun.ttc: 宋体,SimSun:style=Regular 3557 | \end{Verbatim} 3558 | 3559 | 其中第一个是字体文件所在的目录,第二个信息是可以调用的名字,有宋体和SimSun,冒号后面都是tex引擎能够识别的名字。 3560 | 3561 | 3562 | 3563 | 3564 | 3565 | \section{新宏包的安装} 3566 | \label{sec-9} 3567 | 安装texlive-full之后,如果还遇到没有的宏包,可以先到CTAN官网上下载到这个宏包之后,然后将这个宏包解压到系统目录:\\ 3568 | \verb~/usr/share/texmf/tex/latex~ 里面即可。 3569 | 3570 | 当然你也可以在另外一个文件夹里面,这里必须是你的主文件夹下,新建一个文件夹texmf,然后里面新建一个tex,然后再新建一个目录latex,然后在这个latex里面放着你下载下来的宏包。具体比如说有一个宏包名字叫做config,那么latex下面就是config文件夹,然后里面就是config.sty文件。你自己写的宏包扔进去一样有效。 3571 | 唯一要额外做的操作就是在texmf目录之下运行命令: 3572 | \begin{minted}{text} 3573 | sudo texhash 3574 | \end{minted} 3575 | 3576 | 3577 | 3578 | 让texlive把这个目录也加入搜索范围。 3579 | 3580 | 3581 | \subsection{阅读宏包代码} 3582 | \label{sec-9-1} 3583 | 你所接触到的latex宏包源码大多在目录: 3584 | \begin{Verbatim} 3585 | /usr/share/texlive/texmf-dist/tex/latex 3586 | \end{Verbatim} 3587 | 3588 | 3589 | 如果有需要的可以阅读这些代码来学习你正在的sty或者cls文件都是怎么编写的。其中base文件夹里面有book,article,report之类文档类型的定义,也许里面有些命令的原始代码是你需要的。 3590 | 3591 | 3592 | \chapter{利用pandoc输出epub} 3593 | \label{ch:pandoc_epub} 3594 | 一个总的原则就是不要使用太过于花哨的latex特性,本书xelatex基础篇讨论的内容,大多还能兼顾得很好,可能epub那边想要显示的样式会没有,比如你定制了一个自己的罗列环境标签,而在epub那边则总是 \verb+1.+ 之类的,因为epub里面的内容实质上是html,所以这可以通过css来进一步调整,问题不是太大。下面更详细地讨论一些具体的问题。 3595 | 3596 | \begin{itemize} 3597 | \item 图片格式不要选pdf和svg了,就用png或者jpeg,然后图片类型后缀名不要省略了。 3598 | \item 图表环境下label应该跟在caption后面,否则epub那边工作不正常,原因不明。 3599 | \item 数学模式基本上都支持,其在epub中大概是这样的形式 \verb+ 3626 |

右边才是王道。

3627 | 3628 | \end{Verbatim} 3629 | 3630 | 具体分别对应的class是 \verb+flushleft+ , \verb+flushright+ 和 \verb+center+ 。所以你需要在css上添加: 3631 | 3632 | \begin{minted}{css} 3633 | .flushleft{ 3634 | text-align: left!important; 3635 | } 3636 | .flushright{ 3637 | text-align: right!important; 3638 | } 3639 | 3640 | .center{ 3641 | text-align: center !important; 3642 | } 3643 | \end{minted} 3644 | 3645 | 这样显示效果就很接近了。 3646 | 3647 | \subsection{uline命令和sout命令} 3648 | uline和sout这两个命令到epub那边效果不会丢失,sout命令会输出del标签,而uline命令通过css的这一行来达到效果的: 3649 | 3650 | \begin{Verbatim} 3651 | span.underline { 3652 | text-decoration: underline; 3653 | } 3654 | \end{Verbatim} 3655 | 3656 | 3657 | \section{输出epub} 3658 | 用pandoc输出epub命令如下: 3659 | \begin{Verbatim} 3660 | pandoc -o main.epub main.tex --metadata-file=epub.yaml 3661 | \end{Verbatim} 3662 | 3663 | 在\verb+epub.yaml+文件那里你还可以定义一些配置,具体请参看本项目配置参考文件夹下面的 \verb+epub.yaml+ 文件,配套的还有 \verb+epub.css+ 文件,这个css文件在输出epub的时候会混入进去,大体html5那一套东西。 3664 | 3665 | 3666 | \chapter{tikz制图} 3667 | tikz制图我折腾过一段时间,\href{https://github.com/a358003542/tikz_gallery}{这个项目} 读者可以看下。 3668 | 3669 | \chapter{化学相关} 3670 | 化学相关符号甚至非常复杂的有机分子式的显示问题推荐用\emph{chemfig}宏包解决。 3671 | 3672 | 3673 | 3674 | \chapter{其他问题的讨论} 3675 | 3676 | \section{分栏环境备用} 3677 | 不是很推荐这种排版风格了,将图表单独一列,后面跟上文字即可,推荐采用Web风格的瀑布流式布局。 3678 | 3679 | 在实际应用过程中,常常遇到分两栏的情况,但是这两栏宽度是可以自由调整的。我找了一下似乎并没有类似beamer类columns环境那样方便的存在,只好通过minipage命令简单地实现了类似的效果。实际应用我是通过texmaker自定义快捷输入代码模块功能快速输入进文档的。 3680 | \begin{Verbatim} 3681 | \noindent 3682 | \begin{minipage}{\textwidth} 3683 | \begin{minipage}{0.3\textwidth} 3684 | \begin{table}[H] 3685 | \centering 3686 | \medskip 3687 | \scalebox{0.82}{ 3688 | \begin{tabular}{@{}ll@{}} 3689 | \toprule 3690 | $t$(分) & $s$(英尺) \\ \midrule 3691 | 0 & 0 \\ 3692 | 1 & 1200 \\ 3693 | 2 & 4000 \\ 3694 | 3 & 9000 \\ 3695 | 4 & 9500 \\ 3696 | 5 & 9600 \\ 3697 | 6 & 13000 \\ 3698 | 7 & 18000 \\ 3699 | 8 & 23500 \\ 3700 | 9 & 24000 3701 | \\ \bottomrule 3702 | \end{tabular} 3703 | } 3704 | \caption*{表 2-1} 3705 | \end{table} 3706 | 3707 | \end{minipage}\hfill 3708 | \begin{minipage}{0.7\textwidth} 3709 | 3710 | \begin{figure}[H] 3711 | \centering 3712 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{ju-li-shi-jian-qu-xian-tu.png} 3713 | \caption{汽车的距离-时间曲线} 3714 | \label{fig:ju-li-shi-jian-qu-xian-tu} 3715 | \end{figure} 3716 | 3717 | \end{minipage} 3718 | \end{minipage} 3719 | \end{Verbatim} 3720 | 3721 | 最后显示效果如下: 3722 | 3723 | \begin{figure}[H] 3724 | \centering 3725 | \includegraphics[width=\linewidth ,totalheight=0.95\textheight , keepaspectratio]{multicolumn_2.png} 3726 | \end{figure} 3727 | 3728 | 3729 | 3730 | \section{flushright环境空白间距问题} 3731 | flushright环境有一个大型的空白间距,如果你不喜欢这么大的空白间距正如前面谈及的,可以使用raggedright等命令来调整,不过raggedright等命令似乎更适合对图片表格等盒子调整位置(raggedright命令不太好用,有时不知怎么不起作用,推荐就用hfill命令让其他内容居右,唯一要提醒的是hfill命令是针对当前行把内容往右推。) 3732 | 3733 | 那么在段落内如何实现类似word那种一行之类居右对齐? 3734 | 3735 | \begin{Verbatim} 3736 | this is a test line 3737 | 3738 | {\vspace{-\parskip}\hfill some text} 3739 | \end{Verbatim} 3740 | 3741 | 这里推荐先空一行分段,然后用hfill命令将文本推到右边去,然后用vspace调整下距离。这里选择-\textbackslash parskip这样得到的行距和其他行距是一致的。 3742 | 3743 | {\vspace{-\parskip}\hfill 然后我注意到开辟新的竖向模式}\\,比如换行之后,不空一行用smallskip,medskip等,然后不用vspace命令调整也是可以的。因为smallskip也是一种vspace命令的调整模式,但是行距和其他的不太一致,所以在这里推荐就空一段,然后负的parskip。当然如果可以接受不用vspace调整也是可以的。 3744 | 3745 | 3746 | \backmatter 3747 | \part*{附录:参考资料} 3748 | 3749 | \begin{thebibliography}{9} 3750 | \bibitem[lshort]{lshort} 有名的《一份不太简短的\LaTeX2e 介绍》,原版作者:Tobias Oetik\- er,Hubert Partl,Irene Hyna等,版本:2001-08-09,中文翻译:CTeX用户小组,版本:2002-05,pdf下载链接:\\ \href{http://www.ctan.org/tex-archive/info/lshort/chinese}{http://www.ctan.org/tex-archive/info/lshort/chinese}。 3751 | 3752 | \bibitem[latex123]{latex123} 《大家来学\LaTeX 》,原版作者:李果正,版本:2004-03-08,网站链接:\href{http://edt1023.sayya.org/tex/latex123/}{http://edt1023.sayya.org/tex/latex123/}。 3753 | 3754 | \bibitem[wikibook-latex]{wikibook-latex} 维基图书latex篇英文版,版本:2013-08,网站链接\\:\href{http://en.wikibooks.org/wiki/LaTeX}{http://en.wikibooks.org/wiki/LaTeX}。\emph{这本书甚至都没有cite它一下,因为不知道插在哪里,几乎到处都有对它的引用,谢谢所有wikibook的编写者。} 3755 | 3756 | \bibitem[boxes]{boxes} using boxes and glue in \TeX{} and \LaTeX ,原版作者:Nelson H. F. Beebe,版本:2009-03-28,pdf下载链接:链接地址不好复制,请google搜索书名之。 3757 | 3758 | \bibitem[latex-companion]{latex-companion} The Latex Companion 3759 | 3760 | \bibitem[黄帝内经]{黄帝内经} 《黄帝内经》 3761 | 3762 | 3763 | \end{thebibliography} 3764 | 3765 | 3766 | \end{document} 3767 | 3768 | 3769 | 3770 | -------------------------------------------------------------------------------- /mybook.sty: -------------------------------------------------------------------------------- 1 | % mybook.sty 2 | \NeedsTeXFormat{LaTeX2e} 3 | \ProvidesPackage{mybook}[2025/04/29 A simple book config package] 4 | \makeatletter 5 | 6 | % config package options 7 | \PassOptionsToPackage{unicode,colorlinks=true,linkcolor=blue,citecolor=blue}{hyperref} 8 | \PassOptionsToPackage{svgnames,table}{xcolor} 9 | 10 | \newif\if@minted 11 | \newif\if@scripts 12 | \newif\if@headchapter 13 | \@mintedfalse 14 | \@scriptsfalse 15 | \@headchapterfalse 16 | % 定义选项minted 17 | \DeclareOption{minted}{\@mintedtrue} 18 | % 定义选项scripts 19 | \DeclareOption{scripts}{\@scriptstrue} 20 | % 定义选项headchapter 21 | \DeclareOption{headchapter}{\@headchaptertrue} 22 | % 处理未定义的选项 23 | \DeclareOption*{% 24 | \PackageWarning{mybook}{Unknown option `\CurrentOption'}% 25 | } 26 | 27 | % 处理所有选项 28 | \ProcessOptions\relax 29 | 30 | 31 | % basic config 32 | \newlength{\textpt} 33 | \setlength{\textpt}{12pt} 34 | 35 | %========基本必备的宏包========% 36 | \RequirePackage{calc,float,moresize} 37 | %\RequirePackage[onehalfspacing]{setspace} 38 | \linespread{1.5} 39 | %1.3 onehalfspacing 40 | %1.6 doublespacing 41 | \setlength{\emergencystretch}{3em} % prevent overfull lines 42 | 43 | \newcommand{\flypage}[1]{\begin{titlepage}\begin{center}\vspace*{\stretch{1}}{\fontsize{80pt}{40pt}\selectfont\sffamily #1}\vspace*{\stretch{1}}\end{center}\end{titlepage}} 44 | 45 | %===========加入目录 某章或某节=====% 46 | \newcommand{\addchtoc}[1]{ 47 | \cleardoublepage 48 | \phantomsection 49 | \addcontentsline{toc}{chapter}{#1}} 50 | 51 | \newcommand{\addsectoc}[1]{ 52 | \phantomsection 53 | \addcontentsline{toc}{section}{#1}} 54 | 55 | %===========全文基本格式==========% 56 | %段落間距 57 | \setlength{\parskip}{1.6ex plus 0.2ex minus 0.2ex} 58 | \setlength{\parindent}{\textpt * \real{2}} 59 | \RequirePackage{indentfirst} 60 | 61 | 62 | %=========页面设置=========% 63 | \RequirePackage[a4paper, %a4paper size 297:210 mm 64 | bindingoffset=0mm,%裝訂線 65 | top=35mm, %上邊距 包括頁眉 66 | bottom=30mm,%下邊距 包括頁腳 67 | inner=30mm, %左邊距or inner 68 | outer=30mm, %右邊距or outer 69 | headheight=10mm,%頁眉 70 | headsep=15mm,% 71 | footskip=15mm,% 72 | marginparsep=0pt, %旁註與正文間距 73 | marginparwidth=0em,includemp=false% 旁註寬度計入width%旁註寬度 74 | ]{geometry} 75 | 76 | %color 77 | \RequirePackage{xcolor} 78 | 79 | %================字體================% 80 | %设置数学字体 81 | \RequirePackage{amssymb,amsmath} 82 | \RequirePackage{stmaryrd} 83 | \everymath{\displaystyle} 84 | 85 | \RequirePackage{fontspec} 86 | %設置英文字體 87 | \setmainfont[Mapping=tex-text]{DejaVu Serif} 88 | \setsansfont[Mapping=tex-text]{DejaVu Sans} 89 | \setmonofont[Mapping=tex-text]{DejaVu Sans Mono} 90 | 91 | 92 | %中文環境 93 | \RequirePackage{xeCJK} 94 | \xeCJKsetup{PunctStyle=plain} 95 | \setCJKmainfont[FallBack=DejaVu Serif, ItalicFont=KaiTi]{Source Han Serif CN} 96 | \setCJKsansfont[FallBack=DejaVu Sans]{Source Han Sans CN} 97 | \setCJKmonofont[FallBack=DejaVu Sans Mono]{KaiTi} 98 | 99 | 100 | %%===============中文化=========% 101 | \renewcommand\contentsname{目~录} 102 | \renewcommand\listfigurename{插图目录} 103 | \renewcommand\listtablename{表格目录} 104 | \renewcommand\bibname{参~考~资~料} 105 | \renewcommand\indexname{索~引} 106 | \renewcommand\figurename{图} 107 | \renewcommand\tablename{表} 108 | \renewcommand\partname{部分} 109 | \renewcommand\appendixname{附录} 110 | \renewcommand{\today}{\number\year{}年\number\month{}月\number\day{}日} 111 | 112 | 113 | %=======页眉页脚格式=========% 114 | \RequirePackage{fancyhdr} %頁眉頁腳 115 | \RequirePackage{zhnumber} %计数器中文化 116 | \pagestyle{fancy} 117 | 118 | \renewcommand{\sectionmark}[1] 119 | {\markright{第\zhnumber{\arabic{section}}节~~#1}{}} 120 | \renewcommand{\chaptermark}[1] 121 | {\markboth{第\zhnumber{\arabic{chapter}} 章 ~~#1}{}} 122 | 123 | \if@headchapter 124 | \fancypagestyle{plain}{% 125 | \fancyhf{} 126 | \renewcommand{\headrulewidth}{0pt} 127 | \renewcommand{\footrulewidth}{0pt} 128 | \fancyhf[HR]{\ttfamily \footnotesize \leftmark } 129 | \fancyhf[FR]{\thepage}} 130 | \else 131 | \fancypagestyle{plain}{% 132 | \fancyhf{} 133 | \renewcommand{\headrulewidth}{0pt} 134 | \renewcommand{\footrulewidth}{0pt} 135 | \fancyhf[HR]{\ttfamily \footnotesize \rightmark } 136 | \fancyhf[FR]{\thepage}} 137 | \fi 138 | 139 | \pagestyle{plain} 140 | 141 | 142 | %=========章節標題設計=========% 143 | \RequirePackage{titlesec} 144 | %修改part 145 | \titleformat{\part}{\huge\sffamily}{}{0em}{} 146 | %修改chapter 147 | \titleformat{\chapter}{\LARGE\sffamily}{}{0em}{} 148 | %修改section 149 | \titleformat{\section}{\Large\sffamily}{}{0em}{} 150 | %修改subsection 151 | \titleformat{\subsection}{\large\sffamily}{}{0em}{} 152 | %修改subsubsection 153 | \titleformat{\subsubsection}{\normalsize\sffamily}{}{0em}{} 154 | 155 | 156 | %================目录===============% 157 | %toc label to contents space dynamic adjust 158 | \RequirePackage{tocloft}% 159 | \renewcommand{\numberline}[1]{\@cftbsnum #1\@cftasnum~\@cftasnumb} 160 | 161 | %==============超鏈接===============% 162 | %設置書簽和目錄鏈接等 163 | \RequirePackage{hyperref} 164 | %某一小段的引用 165 | \newcommand{\hlabel}[1]{\phantomsection \label{#1}} 166 | 167 | %=================文字強調=========% 168 | \RequirePackage{xeCJKfntef} 169 | 170 | \let\oldemph\emph % Save emph in oldemph 171 | \renewcommand{\emph}[1]{\textcolor{blue}{\textbf{#1}}} 172 | 173 | \RequirePackage[normalem]{ulem} 174 | %波浪线稍微下移点。 175 | \renewcommand{\uwave} 176 | {\bgroup \markoverwith{\lower4.5\p@\hbox{\sixly \char58}}\ULon} 177 | 178 | %==================插入圖片=======% 179 | \RequirePackage{wrapfig} 180 | \RequirePackage{graphicx} 181 | % figure默认存放路径 182 | \graphicspath{{figures/}} 183 | %change the caption style a little like 1-1 184 | \renewcommand{\thefigure}{\arabic{chapter}-\arabic{figure}} 185 | % figure默认浮动控制H 186 | \floatplacement{figure}{H} 187 | 188 | \newenvironment{fig}[2][1] 189 | {\begin{figure}[H] 190 | \centering 191 | \includegraphics[scale=#1 , keepaspectratio]{#2}} 192 | {\end{figure}} 193 | 194 | \newenvironment{linefig}[2][1] 195 | {\begin{figure}[H] 196 | \centering 197 | \includegraphics[width=#1\linewidth ,totalheight=0.95\textheight , keepaspectratio]{#2}} 198 | {\end{figure}} 199 | 200 | 201 | %==============插入表格========% 202 | \RequirePackage{booktabs} 203 | %change the caption style a little like 1-1 204 | \renewcommand{\thetable}{\arabic{chapter}-\arabic{table}} 205 | % 表格行宽放大一点 206 | \renewcommand{\arraystretch}{1.5} 207 | % table默认浮动控制H 208 | \floatplacement{table}{H} 209 | 210 | 211 | % 简单的框线环境 212 | \RequirePackage{framed} 213 | 214 | % 框线表示文章引用 215 | \RequirePackage{mdframed} 216 | \mdfsetup{frametitlealignment=\center} 217 | \newmdenv[frametitlebackgroundcolor=gray!20, linewidth=1pt, 218 | frametitlerulewidth=1pt, frametitlerule=true]{bookref} 219 | 220 | 221 | %========脚注=========% 222 | \RequirePackage{tikz} 223 | \newcommand*\circled[1]{ 224 | \tikz[baseline=(char.base)] 225 | \node[shape=circle,draw,inner sep=0.4pt,minimum size=4pt] (char) {#1};} 226 | 227 | \newcommand*\circledarabic[1]{\circled{\arabic{#1}}} 228 | 229 | \RequirePackage{perpage} %the perpage package 230 | \MakePerPage{footnote} %the perpage package command 231 | 232 | \renewcommand*{\thefootnote}{\protect\circledarabic{footnote}} 233 | 234 | \renewcommand\@makefntext[1]{\vspace{5pt}\noindent 235 | \makebox[20pt][c]{\fontsize{10pt}{12pt}\@thefnmark} 236 | \fontsize{10pt}{12pt}\selectfont #1} 237 | 238 | %main body 与脚注之间的距离 239 | \setlength{\skip\footins}{20pt plus 10pt} 240 | 241 | %插入代码 242 | \RequirePackage{fancyvrb} 243 | \fvset{frame=lines,tabsize=4 ,baselinestretch=1.8, fontsize=\footnotesize} 244 | 245 | 246 | \if@minted 247 | %minted 248 | \RequirePackage{minted} 249 | \setminted{frame=lines, tabsize=4, framesep=10pt, fontsize=\footnotesize} 250 | \fi 251 | 252 | \if@scripts 253 | \NewDocumentCommand{\showCode}{m O{python}}{ 254 | \def\source{\detokenize{scripts/#1}} 255 | 256 | \IfFileExists{\source} 257 | {\inputminted[label=\source]{#2}{\source}} 258 | {file: \source ~not exists.} 259 | } 260 | 261 | \NewDocumentCommand{\showCodeOut}{m}{ 262 | \def\outfile{\detokenize{scripts/#1}} 263 | \IfFileExists{\outfile} 264 | {\VerbatimInput{\outfile}} 265 | {file: \outfile ~not exits.} 266 | } 267 | 268 | \NewDocumentCommand{\showCodeAndOut}{m O{python}}{ 269 | \showCode{#1}[#2] 270 | \showCodeOut{#1.out} 271 | } 272 | \fi 273 | 274 | 275 | \makeatother 276 | \endinput -------------------------------------------------------------------------------- /mybookcover.sty: -------------------------------------------------------------------------------- 1 | % mybookcover.sty 2 | \NeedsTeXFormat{LaTeX2e} 3 | \ProvidesPackage{mybookcover}[2025/04/29 A simple book cover package] 4 | \RequirePackage{mybook} 5 | \RequirePackage{setspace} 6 | 7 | 8 | \makeatletter 9 | 10 | 11 | \renewcommand\title[1]{\def\@title{#1}} 12 | \newcommand\subtitle[1]{\def\@subtitle{#1}} 13 | \renewcommand\author[1]{\def\@author{#1}} 14 | \newcommand\version[1]{\def\@version{#1}} 15 | \renewcommand\date[1]{\def\@date{#1}} 16 | \renewcommand{\today}{\number\year{}年\number\month{}月\number\day{}日} 17 | 18 | \def\@date{\today} 19 | \def\@subtitle{\@latex@warning@no@line{No \noexpand\subtitle given}} 20 | \def\@version{\@latex@warning@no@line{No \noexpand\version given}} 21 | 22 | \newcommand{\makemytitle}{ 23 | \begin{titlepage} 24 | \xeCJKsetup{CJKecglue={\hskip 0pt plus 0.08\baselineskip}} 25 | \newgeometry{left=1cm,right=1cm,top=1cm,bottom=1cm} 26 | \begin{center} 27 | \vspace*{120pt} 28 | {\fontsize{80pt}{40pt}\selectfont\sffamily \@title} 29 | 30 | \vspace{40pt} 31 | {\fontsize{40pt}{20pt}\selectfont\sffamily \@subtitle} 32 | 33 | \vspace{200pt} 34 | {\fontsize{40pt}{20pt}\selectfont\sffamily \@author} 35 | 36 | \vspace{150pt} 37 | {\fontsize{30pt}{20pt}\selectfont\ttfamily \@date \@version} 38 | 39 | \end{center} 40 | \end{titlepage} 41 | \restoregeometry 42 | } 43 | 44 | 45 | \newcommand{\makemytitleA}{ 46 | \begin{titlepage} 47 | \xeCJKsetup{CJKecglue={\hskip 0pt plus 0.08\baselineskip}} 48 | \newgeometry{left=6cm} 49 | \begin{flushleft} 50 | \noindent 51 | \\[-1em] 52 | \color[HTML]{5F5F5F} 53 | \makebox[0pt][l]{ 54 | \textcolor[HTML]{435488}{\rule{1.3\textwidth}{4pt}} 55 | } 56 | \par 57 | \noindent 58 | 59 | { \setstretch{1.4} 60 | \vfill 61 | \noindent {\huge \textbf{\textsf{\@title}}} 62 | \vskip 2em 63 | \noindent 64 | {\Large \textsf{\@author} 65 | \vfill 66 | } 67 | 68 | \textsf{\@date \@version}} 69 | \end{flushleft} 70 | \end{titlepage} 71 | \restoregeometry 72 | } 73 | 74 | \newcommand{\bookcover}[1]{ 75 | \begin{titlepage} 76 | \newgeometry{left=0cm,right=0cm,top=0cm,bottom=0cm,marginparsep=0pt, 77 | marginparwidth=0em,includemp=false} 78 | \tikz[remember picture,overlay]{\node[inner sep=0] at (current page.center) 79 | {\includegraphics[width=\paperwidth,height=\paperheight]{#1}}} 80 | \end{titlepage} 81 | \restoregeometry 82 | } 83 | 84 | \makeatother 85 | \endinput 86 | -------------------------------------------------------------------------------- /配置参考/book_cover/book_cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/配置参考/book_cover/book_cover.png -------------------------------------------------------------------------------- /配置参考/book_cover/book_cover.tex: -------------------------------------------------------------------------------- 1 | \documentclass[12pt,oneside]{book} 2 | 3 | \usepackage{mybook} 4 | \usepackage{mybookcover} 5 | 6 | 7 | \begin{document} 8 | 9 | \title{XeLaTeX指南} 10 | \author{Wander} 11 | 12 | \makemytitle 13 | 14 | \end{document} -------------------------------------------------------------------------------- /配置参考/book_cover/book_cover_ref.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a358003542/xelatex-guide-book/bd840c7cb8d90330540d1d5bc8034579bda816c2/配置参考/book_cover/book_cover_ref.png -------------------------------------------------------------------------------- /配置参考/book_cover/book_cover_ref.tex: -------------------------------------------------------------------------------- 1 | \documentclass[12pt,oneside]{book} 2 | 3 | \usepackage{mybook} 4 | \usepackage{mybookcover} 5 | 6 | 7 | \begin{document} 8 | 9 | \bookcover{book_cover_ref.png} 10 | 11 | 12 | \end{document} -------------------------------------------------------------------------------- /配置参考/epub/epub.css: -------------------------------------------------------------------------------- 1 | body { margin: 5%; text-align: justify; font-size: medium; } 2 | 3 | 4 | pre { 5 | display: block; 6 | padding: 9.5px; 7 | margin: 0 0 10px; 8 | font-size: 13px; 9 | line-height: 1.42857143; 10 | color: #333; 11 | word-break: break-all; 12 | word-wrap: break-word; 13 | background-color: #f5f5f5; 14 | border: 1px solid #ccc; 15 | border-radius: 4px; 16 | } 17 | 18 | code, kbd, pre, samp { 19 | font-family: Menlo,Monaco,Consolas,"Courier New",monospace; 20 | } 21 | 22 | :not(pre)>code { 23 | padding: 2px 4px; 24 | font-size: 90%; 25 | color: #c7254e; 26 | background-color: #f9f2f4; 27 | border-radius: 4px; 28 | } 29 | 30 | 31 | body>p,section>p { 32 | text-indent:2em; 33 | } 34 | h1 { text-align: left; } 35 | h2 { text-align: left; } 36 | h3 { text-align: left; } 37 | h4 { text-align: left; } 38 | h5 { text-align: left; } 39 | h6 { text-align: left; } 40 | 41 | nav#toc ol, 42 | nav#landmarks ol { padding: 0; margin-left: 1em; } 43 | nav#toc ol li, 44 | nav#landmarks ol li { list-style-type: none; margin: 0; padding: 0; } 45 | a.footnote-ref { 46 | position: relative; 47 | vertical-align: super; 48 | font-size: 0.83em; 49 | } 50 | 51 | em, em em em, em em em em em { font-style: italic;} 52 | em em, em em em em { font-style: normal; } 53 | 54 | code{ white-space: pre-wrap; } 55 | 56 | span.smallcaps{ font-variant: small-caps; } 57 | 58 | span.underline{ text-decoration: underline; } 59 | 60 | q { quotes: "“" "”" "‘" "’"; } 61 | 62 | div.column{ display: inline-block; vertical-align: top; width: 50%; } 63 | 64 | blockquote { 65 | font-family: 'KaiTi', 'KaiTi_GB2312', 'STKaiti', 'DejaVu Sans Mono'; 66 | } 67 | 68 | .flushleft{ 69 | text-align: left!important; 70 | } 71 | .flushright{ 72 | text-align: right!important; 73 | } 74 | 75 | .center{ 76 | text-align: center !important; 77 | } -------------------------------------------------------------------------------- /配置参考/epub/epub.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | title: "xelatex指南" 3 | author: "Wander" 4 | creator: "Wander" 5 | date: "2024-2-26" 6 | lang: zh-hans 7 | css: epub.css 8 | cover-image: book_cover.png -------------------------------------------------------------------------------- /配置参考/mybook.sty: -------------------------------------------------------------------------------- 1 | % mybook.sty 2 | \NeedsTeXFormat{LaTeX2e} 3 | \ProvidesPackage{mybook}[2025/04/29 A simple book config package] 4 | \makeatletter 5 | 6 | % config package options 7 | \PassOptionsToPackage{unicode,colorlinks=true,linkcolor=blue,citecolor=blue}{hyperref} 8 | \PassOptionsToPackage{svgnames,table}{xcolor} 9 | 10 | \newif\if@minted 11 | \newif\if@scripts 12 | \newif\if@headchapter 13 | \@mintedfalse 14 | \@scriptsfalse 15 | \@headchapterfalse 16 | % 定义选项minted 17 | \DeclareOption{minted}{\@mintedtrue} 18 | % 定义选项scripts 19 | \DeclareOption{scripts}{\@scriptstrue} 20 | % 定义选项headchapter 21 | \DeclareOption{headchapter}{\@headchaptertrue} 22 | % 处理未定义的选项 23 | \DeclareOption*{% 24 | \PackageWarning{mybook}{Unknown option `\CurrentOption'}% 25 | } 26 | 27 | % 处理所有选项 28 | \ProcessOptions\relax 29 | 30 | 31 | % basic config 32 | \newlength{\textpt} 33 | \setlength{\textpt}{12pt} 34 | 35 | %========基本必备的宏包========% 36 | \RequirePackage{calc,float,moresize} 37 | %\RequirePackage[onehalfspacing]{setspace} 38 | \linespread{1.5} 39 | %1.3 onehalfspacing 40 | %1.6 doublespacing 41 | \setlength{\emergencystretch}{3em} % prevent overfull lines 42 | 43 | \newcommand{\flypage}[1]{\begin{titlepage}\begin{center}\vspace*{\stretch{1}}{\fontsize{80pt}{40pt}\selectfont\sffamily #1}\vspace*{\stretch{1}}\end{center}\end{titlepage}} 44 | 45 | %===========加入目录 某章或某节=====% 46 | \newcommand{\addchtoc}[1]{ 47 | \cleardoublepage 48 | \phantomsection 49 | \addcontentsline{toc}{chapter}{#1}} 50 | 51 | \newcommand{\addsectoc}[1]{ 52 | \phantomsection 53 | \addcontentsline{toc}{section}{#1}} 54 | 55 | %===========全文基本格式==========% 56 | %段落間距 57 | \setlength{\parskip}{1.6ex plus 0.2ex minus 0.2ex} 58 | \setlength{\parindent}{\textpt * \real{2}} 59 | \RequirePackage{indentfirst} 60 | 61 | 62 | %=========页面设置=========% 63 | \RequirePackage[a4paper, %a4paper size 297:210 mm 64 | bindingoffset=0mm,%裝訂線 65 | top=35mm, %上邊距 包括頁眉 66 | bottom=30mm,%下邊距 包括頁腳 67 | inner=30mm, %左邊距or inner 68 | outer=30mm, %右邊距or outer 69 | headheight=10mm,%頁眉 70 | headsep=15mm,% 71 | footskip=15mm,% 72 | marginparsep=0pt, %旁註與正文間距 73 | marginparwidth=0em,includemp=false% 旁註寬度計入width%旁註寬度 74 | ]{geometry} 75 | 76 | %color 77 | \RequirePackage{xcolor} 78 | 79 | %================字體================% 80 | %设置数学字体 81 | \RequirePackage{amssymb,amsmath} 82 | \RequirePackage{stmaryrd} 83 | \everymath{\displaystyle} 84 | 85 | \RequirePackage{fontspec} 86 | %設置英文字體 87 | \setmainfont[Mapping=tex-text]{DejaVu Serif} 88 | \setsansfont[Mapping=tex-text]{DejaVu Sans} 89 | \setmonofont[Mapping=tex-text]{DejaVu Sans Mono} 90 | 91 | 92 | %中文環境 93 | \RequirePackage{xeCJK} 94 | \xeCJKsetup{PunctStyle=plain} 95 | \setCJKmainfont[FallBack=DejaVu Serif, ItalicFont=KaiTi]{Source Han Serif CN} 96 | \setCJKsansfont[FallBack=DejaVu Sans]{Source Han Sans CN} 97 | \setCJKmonofont[FallBack=DejaVu Sans Mono]{KaiTi} 98 | 99 | 100 | %%===============中文化=========% 101 | \renewcommand\contentsname{目~录} 102 | \renewcommand\listfigurename{插图目录} 103 | \renewcommand\listtablename{表格目录} 104 | \renewcommand\bibname{参~考~资~料} 105 | \renewcommand\indexname{索~引} 106 | \renewcommand\figurename{图} 107 | \renewcommand\tablename{表} 108 | \renewcommand\partname{部分} 109 | \renewcommand\appendixname{附录} 110 | \renewcommand{\today}{\number\year{}年\number\month{}月\number\day{}日} 111 | 112 | 113 | %=======页眉页脚格式=========% 114 | \RequirePackage{fancyhdr} %頁眉頁腳 115 | \RequirePackage{zhnumber} %计数器中文化 116 | \pagestyle{fancy} 117 | 118 | \renewcommand{\sectionmark}[1] 119 | {\markright{第\zhnumber{\arabic{section}}节~~#1}{}} 120 | \renewcommand{\chaptermark}[1] 121 | {\markboth{第\zhnumber{\arabic{chapter}} 章 ~~#1}{}} 122 | 123 | \if@headchapter 124 | \fancypagestyle{plain}{% 125 | \fancyhf{} 126 | \renewcommand{\headrulewidth}{0pt} 127 | \renewcommand{\footrulewidth}{0pt} 128 | \fancyhf[HR]{\ttfamily \footnotesize \leftmark } 129 | \fancyhf[FR]{\thepage}} 130 | \else 131 | \fancypagestyle{plain}{% 132 | \fancyhf{} 133 | \renewcommand{\headrulewidth}{0pt} 134 | \renewcommand{\footrulewidth}{0pt} 135 | \fancyhf[HR]{\ttfamily \footnotesize \rightmark } 136 | \fancyhf[FR]{\thepage}} 137 | \fi 138 | 139 | \pagestyle{plain} 140 | 141 | 142 | %=========章節標題設計=========% 143 | \RequirePackage{titlesec} 144 | %修改part 145 | \titleformat{\part}{\huge\sffamily}{}{0em}{} 146 | %修改chapter 147 | \titleformat{\chapter}{\LARGE\sffamily}{}{0em}{} 148 | %修改section 149 | \titleformat{\section}{\Large\sffamily}{}{0em}{} 150 | %修改subsection 151 | \titleformat{\subsection}{\large\sffamily}{}{0em}{} 152 | %修改subsubsection 153 | \titleformat{\subsubsection}{\normalsize\sffamily}{}{0em}{} 154 | 155 | 156 | %================目录===============% 157 | %toc label to contents space dynamic adjust 158 | \RequirePackage{tocloft}% 159 | \renewcommand{\numberline}[1]{\@cftbsnum #1\@cftasnum~\@cftasnumb} 160 | 161 | %==============超鏈接===============% 162 | %設置書簽和目錄鏈接等 163 | \RequirePackage{hyperref} 164 | %某一小段的引用 165 | \newcommand{\hlabel}[1]{\phantomsection \label{#1}} 166 | 167 | %=================文字強調=========% 168 | \RequirePackage{xeCJKfntef} 169 | 170 | \let\oldemph\emph % Save emph in oldemph 171 | \renewcommand{\emph}[1]{\textcolor{blue}{\textbf{#1}}} 172 | 173 | \RequirePackage[normalem]{ulem} 174 | %波浪线稍微下移点。 175 | \renewcommand{\uwave} 176 | {\bgroup \markoverwith{\lower4.5\p@\hbox{\sixly \char58}}\ULon} 177 | 178 | %==================插入圖片=======% 179 | \RequirePackage{wrapfig} 180 | \RequirePackage{graphicx} 181 | % figure默认存放路径 182 | \graphicspath{{figures/}} 183 | %change the caption style a little like 1-1 184 | \renewcommand{\thefigure}{\arabic{chapter}-\arabic{figure}} 185 | % figure默认浮动控制H 186 | \floatplacement{figure}{H} 187 | 188 | \newenvironment{fig}[2][1] 189 | {\begin{figure}[H] 190 | \centering 191 | \includegraphics[scale=#1 , keepaspectratio]{#2}} 192 | {\end{figure}} 193 | 194 | \newenvironment{linefig}[2][1] 195 | {\begin{figure}[H] 196 | \centering 197 | \includegraphics[width=#1\linewidth ,totalheight=0.95\textheight , keepaspectratio]{#2}} 198 | {\end{figure}} 199 | 200 | 201 | %==============插入表格========% 202 | \RequirePackage{booktabs} 203 | %change the caption style a little like 1-1 204 | \renewcommand{\thetable}{\arabic{chapter}-\arabic{table}} 205 | % 表格行宽放大一点 206 | \renewcommand{\arraystretch}{1.5} 207 | % table默认浮动控制H 208 | \floatplacement{table}{H} 209 | 210 | 211 | % 简单的框线环境 212 | \RequirePackage{framed} 213 | 214 | % 框线表示文章引用 215 | \RequirePackage{mdframed} 216 | \mdfsetup{frametitlealignment=\center} 217 | \newmdenv[frametitlebackgroundcolor=gray!20, linewidth=1pt, 218 | frametitlerulewidth=1pt, frametitlerule=true]{bookref} 219 | 220 | 221 | %========脚注=========% 222 | \RequirePackage{tikz} 223 | \newcommand*\circled[1]{ 224 | \tikz[baseline=(char.base)] 225 | \node[shape=circle,draw,inner sep=0.4pt,minimum size=4pt] (char) {#1};} 226 | 227 | \newcommand*\circledarabic[1]{\circled{\arabic{#1}}} 228 | 229 | \RequirePackage{perpage} %the perpage package 230 | \MakePerPage{footnote} %the perpage package command 231 | 232 | \renewcommand*{\thefootnote}{\protect\circledarabic{footnote}} 233 | 234 | \renewcommand\@makefntext[1]{\vspace{5pt}\noindent 235 | \makebox[20pt][c]{\fontsize{10pt}{12pt}\@thefnmark} 236 | \fontsize{10pt}{12pt}\selectfont #1} 237 | 238 | %main body 与脚注之间的距离 239 | \setlength{\skip\footins}{20pt plus 10pt} 240 | 241 | %插入代码 242 | \RequirePackage{fancyvrb} 243 | \fvset{frame=lines,tabsize=4 ,baselinestretch=1.8, fontsize=\footnotesize} 244 | 245 | 246 | \if@minted 247 | %minted 248 | \RequirePackage{minted} 249 | \setminted{frame=lines, tabsize=4, framesep=10pt, fontsize=\footnotesize} 250 | \fi 251 | 252 | \if@scripts 253 | \NewDocumentCommand{\showCode}{m O{python}}{ 254 | \def\source{\detokenize{scripts/#1}} 255 | 256 | \IfFileExists{\source} 257 | {\inputminted[label=\source]{#2}{\source}} 258 | {file: \source ~not exists.} 259 | } 260 | 261 | \NewDocumentCommand{\showCodeOut}{m}{ 262 | \def\outfile{\detokenize{scripts/#1}} 263 | \IfFileExists{\outfile} 264 | {\VerbatimInput{\outfile}} 265 | {file: \outfile ~not exits.} 266 | } 267 | 268 | \NewDocumentCommand{\showCodeAndOut}{m O{python}}{ 269 | \showCode{#1}[#2] 270 | \showCodeOut{#1.out} 271 | } 272 | \fi 273 | 274 | 275 | \makeatother 276 | \endinput -------------------------------------------------------------------------------- /配置参考/mybookcover.sty: -------------------------------------------------------------------------------- 1 | % mybookcover.sty 2 | \NeedsTeXFormat{LaTeX2e} 3 | \ProvidesPackage{mybookcover}[2025/04/29 A simple book cover package] 4 | \RequirePackage{mybook} 5 | \RequirePackage{setspace} 6 | 7 | 8 | \makeatletter 9 | 10 | 11 | \renewcommand\title[1]{\def\@title{#1}} 12 | \newcommand\subtitle[1]{\def\@subtitle{#1}} 13 | \renewcommand\author[1]{\def\@author{#1}} 14 | \newcommand\version[1]{\def\@version{#1}} 15 | \renewcommand\date[1]{\def\@date{#1}} 16 | \renewcommand{\today}{\number\year{}年\number\month{}月\number\day{}日} 17 | 18 | \def\@date{\today} 19 | \def\@subtitle{\@latex@warning@no@line{No \noexpand\subtitle given}} 20 | \def\@version{\@latex@warning@no@line{No \noexpand\version given}} 21 | 22 | \newcommand{\makemytitle}{ 23 | \begin{titlepage} 24 | \xeCJKsetup{CJKecglue={\hskip 0pt plus 0.08\baselineskip}} 25 | \newgeometry{left=1cm,right=1cm,top=1cm,bottom=1cm} 26 | \begin{center} 27 | \vspace*{120pt} 28 | {\fontsize{80pt}{40pt}\selectfont\sffamily \@title} 29 | 30 | \vspace{40pt} 31 | {\fontsize{40pt}{20pt}\selectfont\sffamily \@subtitle} 32 | 33 | \vspace{200pt} 34 | {\fontsize{40pt}{20pt}\selectfont\sffamily \@author} 35 | 36 | \vspace{150pt} 37 | {\fontsize{30pt}{20pt}\selectfont\ttfamily \@date \@version} 38 | 39 | \end{center} 40 | \end{titlepage} 41 | \restoregeometry 42 | } 43 | 44 | 45 | \newcommand{\makemytitleA}{ 46 | \begin{titlepage} 47 | \xeCJKsetup{CJKecglue={\hskip 0pt plus 0.08\baselineskip}} 48 | \newgeometry{left=6cm} 49 | \begin{flushleft} 50 | \noindent 51 | \\[-1em] 52 | \color[HTML]{5F5F5F} 53 | \makebox[0pt][l]{ 54 | \textcolor[HTML]{435488}{\rule{1.3\textwidth}{4pt}} 55 | } 56 | \par 57 | \noindent 58 | 59 | { \setstretch{1.4} 60 | \vfill 61 | \noindent {\huge \textbf{\textsf{\@title}}} 62 | \vskip 2em 63 | \noindent 64 | {\Large \textsf{\@author} 65 | \vfill 66 | } 67 | 68 | \textsf{\@date \@version}} 69 | \end{flushleft} 70 | \end{titlepage} 71 | \restoregeometry 72 | } 73 | 74 | \newcommand{\bookcover}[1]{ 75 | \begin{titlepage} 76 | \newgeometry{left=0cm,right=0cm,top=0cm,bottom=0cm,marginparsep=0pt, 77 | marginparwidth=0em,includemp=false} 78 | \tikz[remember picture,overlay]{\node[inner sep=0] at (current page.center) 79 | {\includegraphics[width=\paperwidth,height=\paperheight]{#1}}} 80 | \end{titlepage} 81 | \restoregeometry 82 | } 83 | 84 | \makeatother 85 | \endinput 86 | -------------------------------------------------------------------------------- /配置参考/pdf_book.tex: -------------------------------------------------------------------------------- 1 | % !Mode:: "TeX:UTF-8" 2 | 3 | \documentclass[12pt,oneside]{book} 4 | 5 | \usepackage{mybook} 6 | \usepackage{mybookcover} 7 | 8 | 9 | \title{notebook} 10 | \author{Wander} 11 | \hypersetup{ 12 | pdftitle={notebook}, 13 | pdfauthor={Wander}, 14 | pdfcreator={Wander}, 15 | pdfsubject={subject}, 16 | } 17 | 18 | 19 | \begin{document} 20 | \makemytitle 21 | 22 | \flypage{感谢上帝} 23 | 24 | 25 | \frontmatter 26 | \addchtoc{序言} 27 | \chapter*{序言} 28 | 29 | 30 | \addchtoc{目录} 31 | \setcounter{tocdepth}{2} 32 | \tableofcontents 33 | 34 | 35 | 36 | \mainmatter 37 | 38 | 39 | 40 | \part{生活} 41 | 42 | 43 | 44 | \chapter{留肾精} 45 | 46 | 47 | \appendix 48 | \part{附录} 49 | \chapter{术语释义} 50 | 51 | 52 | 53 | \backmatter 54 | \chapter*{参考资料} 55 | \addchtoc{参考资料} 56 | \begin{thebibliography}{99} 57 | \bibitem[黄帝内经]{黄帝内经} 《黄帝内经》. 58 | 59 | 60 | \end{thebibliography} 61 | 62 | 63 | \end{document} 64 | 65 | 66 | -------------------------------------------------------------------------------- /配置参考/pdf_paper.tex: -------------------------------------------------------------------------------- 1 | % !TEX TS-program = xelatex 2 | 3 | % 根据 https://www.overleaf.com/latex/templates/constructions/vqhvxmnfgcbh 4 | % 改动而成 5 | 6 | \documentclass[12pt,a4paper,twoside]{article} 7 | \newlength{\textpt} 8 | \setlength{\textpt}{12pt} 9 | 10 | \usepackage[T1]{fontenc} 11 | \usepackage{tabularx, colortbl} 12 | \usepackage[margin=3cm]{geometry} 13 | \usepackage{xcolor} 14 | \definecolor{ochre}{RGB}{204, 119, 34} 15 | \usepackage[colorlinks=true,linkcolor=black,citecolor=black,filecolor=magenta,urlcolor=ochre]{hyperref} 16 | 17 | \usepackage[final,nopatch=footnote]{microtype} 18 | 19 | \usepackage{ 20 | enumitem, 21 | multicol, 22 | multirow, 23 | linguex, 24 | amssymb, 25 | microtype, 26 | stmaryrd, 27 | amsmath, 28 | booktabs, 29 | calculator, 30 | verbatim, 31 | titling, 32 | fontspec, 33 | changepage, 34 | float, 35 | multirow 36 | } 37 | 38 | % Paper license 39 | \usepackage[ 40 | type={CC}, 41 | modifier={by}, 42 | version={4.0}, 43 | ]{doclicense} 44 | 45 | % set bibliography style 46 | \bibliographystyle{unified} 47 | 48 | %================字體================% 49 | %設置英文字體 50 | \setmainfont[Mapping=tex-text]{DejaVu Serif} 51 | \setsansfont[Mapping=tex-text]{DejaVu Sans} 52 | \setmonofont[Mapping=tex-text]{DejaVu Sans Mono} 53 | 54 | %中文環境 55 | \RequirePackage[]{xeCJK} 56 | \xeCJKsetup{PunctStyle=plain} 57 | \setCJKmainfont[FallBack=DejaVu Serif, ItalicFont=KaiTi]{Source Han Serif CN} 58 | \setCJKsansfont[FallBack=DejaVu Sans]{Source Han Sans CN} 59 | \setCJKmonofont[FallBack=DejaVu Sans Mono]{KaiTi} 60 | 61 | 62 | % packages: 63 | \usepackage[]{titlesec} 64 | \usepackage[hang]{footmisc} 65 | \usepackage[nocenter]{qtree} 66 | \usepackage[normalem]{ulem} 67 | \usepackage{graphicx} 68 | \usepackage{fancyhdr} 69 | 70 | % 默认图片地址 71 | \graphicspath{{figures/}} 72 | 73 | \setlength{\intextsep}{4pt plus 2pt minus 2pt} 74 | \renewcommand{\firstrefdash}{} 75 | % 中文行间距还是需要稍微拉大点 76 | % 格式略微调整 77 | \linespread{1.3} 78 | \setlength{\parindent}{2em} 79 | \RequirePackage{indentfirst} 80 | \setlength{\parskip}{1.6ex} 81 | 82 | \newcommand{\ii}{\={i}} 83 | \newcommand{\red}[1]{\textcolor{red}{#1}} 84 | \newcommand{\Reference}{\\ \textcolor{white}{.}\hfill} 85 | 86 | % header style for all but first page 87 | \pagestyle{fancy} 88 | \fancyhf{} 89 | \renewcommand{\headrulewidth}{0pt} 90 | 91 | % header style for first page 92 | \fancypagestyle{plain}{% 93 | \fancyhf{}% clear all header and footer fields 94 | \renewcommand{\footrulewidth}{0.4pt} 95 | \lfoot{ } 96 | \rfoot{\thepage}% 97 | } 98 | 99 | 100 | % set head height 101 | \setlength{\headheight}{14.49998pt} 102 | 103 | \titleformat*{\section}{\large\bfseries} 104 | \titleformat*{\subsection}{\normalsize\bfseries} 105 | \titlespacing*{\section}{0em}{15pt}{10pt} 106 | 107 | 108 | % for vertical centering text in tabularx X column 109 | \renewcommand\tabularxcolumn[1]{m{#1}} 110 | 111 | % column types for tabularx 112 | \newcolumntype{L}{>{\raggedright\arraybackslash}X} 113 | \newcolumntype{R}{>{\raggedleft\arraybackslash}X} 114 | \newcolumntype{C}{>{\centering\arraybackslash}X} 115 | 116 | \usepackage{caption} 117 | \captionsetup{font=footnotesize} 118 | 119 | 120 | % no vertical space in lists 121 | \setlist{nosep} 122 | 123 | % remove vertical space after verbatim environment 124 | \usepackage{etoolbox} 125 | \makeatletter 126 | \preto{\@verbatim}{\topsep=0pt \partopsep=0pt } 127 | \makeatother 128 | 129 | % enumitem package seems to override this 130 | % behavior, so we also add 131 | % (thanks to https://tex.stackexchange.com/questions/43331/control-vertical-space-before-and-after-verbatim-environment) 132 | \AtBeginEnvironment{verbatim}{\setlist[trivlist]{nolistsep}} 133 | 134 | 135 | \fancyhead[LO]{} 136 | \fancyhead[RE]{} 137 | \fancyhead[RO, LE]{\thepage} 138 | 139 | 140 | \raggedbottom 141 | \begin{document} 142 | 143 | 144 | % make sure that first page doesn't 145 | % have running heads: 146 | \thispagestyle{plain} 147 | 148 | % first page header: 149 | % DOI and Creative Commons license 150 | \newcolumntype{Y}{>{\raggedleft\arraybackslash}X} 151 | 152 | % 此处输入doi 一些文献管理软件比如zotero会自动解析出很多信息 153 | \noindent 154 | \begin{tabularx}{\textwidth}{XY} 155 | \doclicenseImage[imagewidth=0.5\linewidth] & \small{doi{10.1093/mind/LIX.236.433}} \\ 156 | \end{tabularx} 157 | 158 | \vspace{30pt} 159 | 160 | % 标题 161 | \begin{center} 162 | \LARGE{\textbf{计算机器与智能}} 163 | \end{center} 164 | 165 | % 作者信息 166 | \begin{center} 167 | \vspace{4pt} 168 | \large 169 | Alan M. Turing 170 | \end{center} 171 | 172 | 173 | % 摘要 174 | \begin{small} 175 | \begin{center} 176 | \vspace{9pt} 177 | \textbf{Abstract} 178 | \end{center} 179 | 180 | \begin{adjustwidth}{20pt}{20pt} 181 | 1950年,后来被誉为“计算机科学之父”和“人工智能先驱”的艾伦·图灵(Alan M. Turing)发表了划时代论文《计算机器与智能》(Computing Machinery and Intelligence),探讨“机器是否能思考”这一根本问题。文中图灵设计了“模仿游戏”(Imitation Game)的思想实验,这就是后世广为人知的“图灵测试”。然而,透过“图灵测试”的光环仔细研读,会发现图灵在文中表达了对机器与智能远远更为深刻的思考。为此集智俱乐部AGI社区【何瑞杰、徐博文、刘兆庭、冯睿洋| 翻译】对这篇经典论文做了完整翻译,希望能够回归本源,探讨其丰厚内涵,也希望对读者有所启发。 182 | \end{adjustwidth} 183 | 184 | 185 | \end{small} 186 | 187 | 188 | \vspace{10pt} 189 | \section{模仿游戏} 190 | 考虑以下问题:“机器能思考吗?”(Can machines think?)要回答这个问题,首先需要定义“机器”和“思考”这两个术语。定义的表述或许要尽可能反映这两个词的通常用法,但这种看法是危险的。如果我们通过考察这两个词的通常用法来找到它们的含义,那么很难避免得出这样的结论:这两个词的含义和“机器能思考吗”这一问题的答案,将在“盖洛普民意测验”之类的统计调查中寻求。这是荒谬的。我并不试图给出这样的定义,而是提出另一个问题,它与原问题密切相关,并用相对清晰的词汇表达。 191 | 192 | 新的问题可以通过一个游戏来描述,称之为“模仿游戏”(imitation game)。游戏中有一个男人(A)、一个女人(B)和一个提问者(C,不论男女)。提问者待在一个与另外两人相隔离的屋子里,其目标是判断出外面哪个是男人、哪个是女人。提问者用标签 X、Y 指称外面的两个人。游戏结束时,他要说出“X 是 A,Y 是 B”或者“X 是 B,Y 是 A”。例如,提问者 C 可以向 A 和 B 提出下面这样的问题: 193 | 194 | 195 | 196 | 197 | 198 | \begin{thebibliography}{99} 199 | \bibitem{1} Samuel Butler, Erewhon, London, 1865. Chapters 23, 24, 25, The Book of the Machines. 200 | \bibitem{2} Alonzo Church, An Unsolvable Problem of Elementary Number Theory”, American J. of Math., 58(1936), 345–363. 201 | \bibitem{3} K. Gödel, Über formal unentscheildbare Sätze der Principia Mathematica und verwandter Sys- teme, I”, Monatshefle für Math. und Phys. , (1931), 173–189. 202 | \bibitem{4} D. R. Hartree, Calculating Instruments and Machines, New York, 1949. 203 | \bibitem{5} S. C. Kleene, General Recursive Functions of Natural Numbers ”, American J. of Math., 57(1935), 153–173 and 219–244. 204 | \bibitem{6} G. Jefferson, The Mind of Mechanical Man”. Lister Oration for 1949. British Medical Journal, vol.i (1949), 1105–1121. 205 | \bibitem{7} Countess of Lovelace, Translator’s notes te an article on Babbage’s Analytical Engire”, Scientific Memoirs (ed. by R. Taylor), vol.3 (1842), 691–731. 206 | \bibitem{8} Bertrand Russell, History of Western Philosophy, London, 1940. 207 | \bibitem{9} A. M. Turing, On Computable Numbers, with an Application to the Entscheidungsproblem”,Proc.London Math.Soc. (2), 42 (1937), 230–265. Victoria University of Manchester. 208 | 209 | \end{thebibliography} 210 | 211 | \end{document} --------------------------------------------------------------------------------