如何解决latex中将公式放到表格中后公式字体变小的问题
在 LaTeX 中,将公式放入表格中可能导致公式字体变小的问题。这是因为表格默认使用了较小的字号。要解决这个问题,可以通过在表格中使用 \displaystyle 命令或者使用 array 宏包的 >{\displaystyle}c 来强制将公式显示为正常字号。下面是两种解决方案的示例代码:
方法一:使用 \displaystyle 命令
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{table}
\caption{示例表格}
\centering
\begin{tabular}{|c|c|}
\hline
\textbf{公式} & \textbf{说明} \\
\hline
$\displaystyle \frac{1}{2} \left( \frac{a}{b} \right)$ & 这是一个示例公式 \\
\hline
\end{tabular}
\end{table}
\end{document}
方法二:使用 array 宏包的 >{\displaystyle}c
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\begin{document}
\begin{table}
\caption{示例表格}
\centering
\begin{tabular}{|>{\displaystyle}c|c|}
\hline
\textbf{公式} & \textbf{说明} \\
\hline
\frac{1}{2} \left( \frac{a}{b} \right) & 这是一个示例公式 \\
\hline
\end{tabular}
\end{table}
\end{document}
LATEX表格如何设置偶数行为灰色背景
在 LaTeX 中,可以使用 xcolor 宏包来设置表格的偶数行为灰色背景。下面是一个示例代码,展示了如何实现这个效果:
\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}
\rowcolors{2}{gray!25}{white} % 将偶数行设置为灰色背景,奇数行为白色背景
\centering
\begin{tabular}{|c|c|c|}
\hline
\rowcolor{gray!50} % 设置表头为灰色背景
\textbf{列1} & \textbf{列2} & \textbf{列3} \\
\hline
数据1 & 数据2 & 数据3 \\
数据4 & 数据5 & 数据6 \\
数据7 & 数据8 & 数据9 \\
\hline
\end{tabular}
\caption{示例表格}
\end{table}
\end{document}
Latex参考文献分章编译
该方法仅适用于支持 biblatex 包的模板。
\documentclass{book}
\usepackage[backend=biber, style=numeric, refsection=chapter]{biblatex}
\addbibresource{references.bib} % 这里替换为您的.bib文件
\begin{document}
\tableofcontents
\chapter{引言}
\begin{refsection}
% 章节内容...
\printbibliography[heading=subbibliography]
\end{refsection}
% 其他章节...
% 在目录中添加无编号的参考文献小节
\printbibliography[heading=bibintoc, title={参考文献}]
\addcontentsline{toc}{chapter}{参考文献}
\end{document}
VS CODE 自动补全
公式补齐
功能:输入$
,自动出现$$
并且光标位于中间。
方法:
首先使用Everything搜索\syntax\latex-language-configuration.json,我的文件路径是
C:\Users\Administrator\.vscode\extensions\james-yu.latex-workshop-10.1.0\syntax\latex-language-configuration.json
文件路径仅供大家参考,每个人的版本号不太一样。
然后在latex-language-configuration.json文件中搜索autoClosingPairs,在其中添加["$", "$"]
即可。
Figure环境补齐
这个功能其实就是用户自定义代码块。latex自带的figure环境只能显示
\begin{figure}
\end{figure}
通过用户自定义代码块,输入figure,选择插入figure环境后,可以自动出现完整的figure代码,包括图片大小,图标题和图标签。
\begin{figure}[htbp]
\centering
\includegraphics[width=\textwidth]{XXX.png}
\caption{Caption.}
\label{Fig:label}
\end{figure}
方法:
- 打开User snippets命令面板(Files --> Preferences --> User snippets或ctrl + shift +P直接打开命令面板,输入 Configure User Snippets)
- 输入latex,定位至latex.json
- latex.jon文件中有默认的语法格式,我们只需要在大括号中加入以下内容即可
"Insert Figure Environment": {
"prefix": "figure",
"body": [
"\\begin{figure}[htbp]",
"\\centering",
"\\includegraphics[width=\\textwidth]{${1:XXX.png}}",
"\\caption{${2:Caption.}}",
"\\label{${3:Fig:label}}",
"\\end{figure}"
],
"description": "Insert a complete figure environment"
}
latexdiff
参考教程: