刷到....
刷到....
这是普通的行间距。对于中文,会被ctex通过默认的scheme=chinese设置为1.3倍...
如果你确实希望缩短全文的中文行距,可以用:scheme=plain...

同时enumitem提供了noitemsep,最好不要手动以不准确的方式微调参数:

\documentclass[
a4paper,11pt,
scheme=plain% 不修该行距为1.3倍
]{ctexart}
\usepackage{enumitem}
\usepackage{zhlipsum}
\begin{document}
\begin{enumerate}[label={\Alph*.}]%
\item 有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?
\item 有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?
\item 有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?
\end{enumerate}
\bigskip
\begin{enumerate}[label={\Alph*.},noitemsep]%
\item 有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?
\item 有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?
\item 有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?有非法关键字?
\end{enumerate}
\bigskip
下面这个中文段落行距太窄并不好看...
\zhlipsum[2]
\end{document}
\documentclass[a4paper,11pt]{article}
\usepackage{enumitem}
\usepackage{lipsum}
\begin{document}
\begin{enumerate}[label={\Alph*.}]%
\item \lipsum[1][1-3]
\item \lipsum[1][1-3]
\item \lipsum[1][1-3]
\item \lipsum[1][1-3]
\end{enumerate}
\bigskip
\begin{enumerate}[label={\Alph*.},noitemsep]%
\item \lipsum[1][1-3]
\item \lipsum[1][1-3]
\item \lipsum[1][1-3]
\item \lipsum[1][1-3]
\end{enumerate}
\end{document}
\documentclass[a4paper,11pt]{ctexart}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\begin{document}
如果既想要正文的行距保持正常,又想要只在\texttt{enumerate}环境内让行距变得紧凑...
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
\begin{enumerate}[%
itemsep=-1.8mm,label={\Alph*.},
before=\linespread{1.0}\selectfont
]
\item 我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体
\item 我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体
\item 我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体我能吞下玻璃而不伤身体
\end{enumerate}
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
我能吞下玻璃而不伤身体
不过这是不太好的...因为行文的行距就不一致了,是不太好的排版...
\end{document}
maybe related to \quotation:
如果先暂时不看abstract宏包和
\setlength{\absleftindent}{0pt} %取消左边距
\setlength{\absrightindent}{0pt} %取消右边距
\renewcommand{\abstracttextfont}{\normalsize} %确保摘要环境内外字号一致的设置...
% line 366~408 article.cls
\if@titlepage
....
\else
\newenvironment{abstract}{%
\if@twocolumn
\section*{\abstractname}%
\else
\small
\begin{center}%
{\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
\end{center}%
\quotation
\fi}
{\if@twocolumn\else\endquotation\fi}
\fi
...
\newenvironment{quotation}
{\list{}{\listparindent 1.5em%
\itemindent \listparindent
\rightmargin \leftmargin
\parsep \z@ \@plus\p@}%
\item\relax}
{\endlist}其中在abstarct中的首行缩进名为\listparindent 1.5em.可见下例。
\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
\parindent=0em
\makeatletter
\renewenvironment{abstract}{%
\if@twocolumn
\section*{\abstractname}%
\else
\small
\begin{center}%
{\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
\end{center}%
\quotation
\fi}
{\if@twocolumn\else\endquotation\fi}
\renewenvironment{quotation}
{\list{}{%
\listparindent 1.5em% %<-important here
\itemindent \listparindent
\rightmargin \leftmargin
\parsep \z@ \@plus\p@}%
\item\relax}
{\endlist}
\makeatother
\begin{document}
\lipsum[2]
\begin{abstract}
\lipsum[2]
\end{abstract}
\lipsum[2]
\end{document}
哇...根源貌似找到了:abstract环境内又嵌套了quotation环境,而quotation环境内主动将itemindent的值设为了\listparindent。
对的。
那请问怎么少改动的“使内的与外的一致”呢,从局部优先的特征来看只能重定义整个quotation环境了吗...我感觉重定义quotation也并不太好,这可能影响正文中正常使用quotation环境。
「怎么少改动的“使内的与外的一致”呢?」按我理解的需求是:
abstract内的首行间距与\parindent一致quotation环境的正常使用我感觉把\quotation复制一份使用\parindent的版本\myquotation专门用于abstarct也许会更好(?)例如这样:
\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
\usepackage{etoolbox}
\makeatletter
\NewCommandCopy{\myquotation}{\quotation}
\renewcommand\myquotation{%
\list{}{%\listparindent 1.5em%
\itemindent \parindent %\listparindent
\rightmargin \leftmargin
\parsep \z@ \@plus\p@}%
\item\relax
}
\patchcmd{\abstract}{\quotation}{\myquotation}{}{}
\makeatother
\parindent=0em
\begin{document}
\begin{quotation}
\lipsum[2][1-5]
\end{quotation}
\lipsum[2][1-5]
\begin{abstract}
\lipsum[2][1-5]
\begin{quotation}
\lipsum[2][1-5]
\end{quotation}
\end{abstract}
\lipsum[2]
\begin{quotation}
\lipsum[2][1-5]
\end{quotation}
\end{document}
此时对于正文段落的间距\parindent似乎是一致了,但对于enumerate似乎仍有问题...
\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
\usepackage{abstract}
\setlength{\absleftindent}{0pt}
\setlength{\absrightindent}{0pt}
\renewcommand{\abstracttextfont}{\normalsize}
\usepackage{etoolbox}
\makeatletter
\NewCommandCopy{\myquotation}{\quotation}
\renewcommand\myquotation{%
\list{}{%\listparindent 1.5em%
\itemindent \parindent%\listparindent
\rightmargin \leftmargin
\parsep \z@ \@plus\p@}%
\item\relax
}
\patchcmd{\abstract}{\quotation}{\myquotation}{}{}
\makeatother
\parindent=4em
\begin{document}
\lipsum[2][1-5]
\begin{abstract}
\lipsum[2][1-5]
\begin{enumerate}
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
\end{enumerate}
\end{abstract}
\lipsum[2]
\begin{enumerate}
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
\end{enumerate}
\end{document}
沉默...
把评论区中的测试代码搬到我们的目标「希望abstract环境」和「正文环境」保持一致,注意quotation环境中实际上就是一个\list,既然我们想要和正文一致,不妨直接(非常暴力地)把\myquotation置为空,这样似乎就不会受到:
\listparindent 1.5em%
\itemindent \listparindent
\rightmargin \leftmargin
\parsep \z@ \@plus\p@的影响了...(因为原先abstract内部就借用了quotation内部也借用了\list,所以在abstract内部用enumerate实际上是"list in list"...)
这样的话,也不需要abstract宏包调整字号了,直接从底层自定义想要的abstract环境...(嗯我也不知道好不好...)
\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
%% 不用 abstract 宏包,自力更生吧...
\usepackage{etoolbox}
\patchcmd{\abstract}{\small}{}{}{}
\patchcmd{\abstract}{\quotation}{}{}{}
\patchcmd{\endabstract}{\endquotation}{}{}{}
\newcommand\txt{This is some txt txt txt txt txt txt. }
\newcommand\mytxt{\txt\txt\txt\txt\txt\txt}
\newcommand*\printvalue[1]{\texttt{\string #1} : \the #1}
\parindent=2em % 为了适应「10.」的两位数缩进稍微调大了...
\usepackage{enumitem}
\setlist{
align=left,
leftmargin=0pt,
itemindent=\parindent,
labelindent=0pt,
labelwidth=!,
}
\begin{document}
\makeatletter
\texttt{\meaning\abstract}
\texttt{\meaning\endabstract}
\makeatother
\lipsum[2][1-5]
\begin{abstract}
\lipsum[2][1-5]
\begin{enumerate}[start=8]
\item \printvalue\leftmargin
\item \printvalue\itemindent
\item \printvalue\labelsep
\item \printvalue\labelwidth
\item \printvalue\labelindent
\item \mytxt
\end{enumerate}
\end{abstract}
\lipsum[2]
\begin{enumerate}[start=8]
\item \printvalue\leftmargin
\item \printvalue\itemindent
\item \printvalue\labelsep
\item \printvalue\labelwidth
\item \printvalue\labelindent
\item \mytxt
\end{enumerate}
\end{document}
1.mwea在这里起的作用是?
2.是不是可以理解成,你希望:
cnt=5\cmd*带星号,不会自动清零(resume),这将导致cnt=6\cmd*带星号,同样不会自动清零(resume),这将导致cnt=7\cmd不带星号,自动清零,这将导致cnt=0清零之后自增cnt=1\cmd*带星号,不会自动清零(resume),这将导致cnt=2 ?3.该问题如果与beamer无关,则mwe最好用article或者book
\documentclass{beamer}
\newif\ifresume %<- add newif condition
\resumefalse
\newcommand{\separateline}[1]{%
\hrulefill\ $\downarrow$ #1 $\downarrow$\ \hrulefill%
}
\newcounter{mwea}
\newcounter{mweb}
\newcommand{\mwea}{%
\stepcounter{mwea}%
\ifresume
\setcounter{mweb}{1}%
\fi
cnt mwea's value is \themwea. \par%
}
\newcommand{\mweb}{%
\stepcounter{mweb}%
cnt mweb's value is \themweb. \par%
}
\begin{document}
\frame{
\ttfamily\small
\separateline{first layer}
\mwea \mweb \mweb \mweb
\separateline{second layer}
\mwea \mweb \mweb \mweb
\separateline{third layer}
\mwea \mweb \mweb \mweb
\resumetrue%<- change the condition
\separateline{fourth layer}
\mwea \mweb \mweb \mweb
}
\end{document}
\documentclass{beamer}
\newcommand{\separateline}[1]{%
\hrulefill\ $\downarrow$ #1 $\downarrow$\ \hrulefill%
}
\newcounter{mwea}
\newcounter{mweb}
\NewDocumentCommand{\mwea}{s}{%
\stepcounter{mwea}%
\IfBooleanF{#1}{\setcounter{mweb}{1}}%
cnt mwea's value is \themwea. \par%
}
\newcommand{\mweb}{%
\stepcounter{mweb}%
cnt mweb's value is \themweb. \par%
}
\begin{document}
\frame{
\ttfamily\small
\separateline{first layer}
\mwea* \mweb \mweb \mweb
\separateline{second layer}
\mwea* \mweb \mweb \mweb
\separateline{third layer}
\mwea \mweb \mweb \mweb %<- clear the mweb here
\separateline{fourth layer}
\mwea* \mweb \mweb \mweb
}
\end{document}
可以试试luadraw宏包:
当然,这需要手动安装,也需要lualatex。
如果要画的函数没有简单的极坐标公式的话,这种方式可能是最具有拓展性的。
\documentclass[border=4pt]{standalone}
\usepackage{luadraw}
\begin{document}
\begin{luadraw}{name=implicit_function}
local g = graph:new{window={-3,3,0,2},size={10,10}}
g:Linecap("round")
g:Saveattr(); g:Viewport(-2.5,-.5,0,2); g:Coordsystem(-2,2,-2,2,true)
local F = function(x,y) return (x^2+y^2)^2 - 2 * 4 * x * y end
g:Dimplicit(F,{grid={500,500},draw_options="thick"})
g:Daxes(
{0,2.5,2.5},{arrows="-latex",legend={"$x$","$y$"},labelpos={"top","right"},originpos={"none","none"}}
)
g:Restoreattr()
g:Saveattr(); g:Viewport(2.5,0,0,2); g:Coordsystem(-2.5,2.5,-2,2,true)
local G = function(x,y) return (x^2+y^2)^2 - 4 * (x^2 - y^2) end
g:Dimplicit(G,{grid={500,500},draw_options="thick"})
g:Daxes(
{0,3,3},{arrows="-latex",legend={"$x$","$y$"},labelpos={"top","right"},originpos={"none","none"}}
)
g:Restoreattr()
g:Show()
\end{luadraw}
\end{document} 
不知道效果对不对...

but why not \visible<\thenaturevisible->{#2} instead of \visible<thenaturevisible->{#2}?

你可以试试「只有法语文档」的luadraw宏包:
% https://ask.latexstudio.net/ask/question/7513.html
\documentclass{standalone}
\usepackage{luadraw}
\begin{document}
\begin{luadraw}{name=implicit_function}
local g = graph:new{window={-3,3,-3,3},size={10,10}}
g:Linecap("round")
local F = function(x,y) return x^2+y^2+x*y-1 end
g:Dimplicit(F,{draw_options="thick"})
g:Dgradbox(
{Z(-2,-2),Z(2,2),1,1},{grid=true,title="\\textbf{Implicit Function Plot}"}
)
g:Show()
\end{luadraw}
\end{document}
\documentclass{standalone}
\usepackage{luadraw}
\begin{document}
\begin{luadraw}{name=implicit_function_tangentline}
local g = graph:new{window={-3,3,-3,3},size={10,10}}
g:Linecap("round")
% https://github.com/pfradin/luadraw/blob/a2759c0aeaf73e023362fac960ffdf704470925a/files/luadraw_lines.lua#L406-L421
local DtangentI = function(f,x0,y0,len,draw_options) -- f:(x,y()) -> f(x,y)
-- We assume that f(x0,y0)=0!
local h = 1e-6
local A = Z(x0,y0) -- 定义复数点(x0,y0)
local a,b = (f(x0+h,y0)-f(x0-h,y0))/(2*h), (f(x0,y0+h)-f(x0,y0-h))/(2*h)
-- 定义 a,b 为f(x0)处的两个偏导数
local v = Z(-b,a)
if len == nil then -- 如果传入的参数为空,则绘制整条直线
g:Dline({A,v},draw_options)
else
local u = len*v/cpx.abs(v)/2 -- 否则往两侧绘制长度为 len/2 的线段
g:Dseg({A-u,A+u},draw_options) -- 绘制线段
end
end
local F = function(x,y) return x^2+y^2+x*y-1 end
g:Dimplicit(F,{draw_options="thick"})
g:Dgradbox(
{Z(-2,-2),Z(2,2),1,1},{grid=true,title="\\textbf{Implicit Function Plot}"}
)
local x0 = 1/2
local L = solve(function(t) return F(x0,t) end,-2,2) -- 求解两个根获得直线的y_i坐标
for _, y in ipairs(L) do -- 循环绘制多条切线
DtangentI(F,x0,y,2,"thick,red") -- This work!
end
g:Show()
\end{luadraw}
\end{document}
Thanks to Jasper Habicht!
一个可能的答案如下:
\documentclass{article}
\usepackage{libertinus-otf}
\usepackage[landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{functional, tikz}
\IgnoreSpacesOn
\tlNew \gTikzPathsTlpositive
\tlNew \gTikzPathsTlnegative
\clistNew \lCurrentRowDataClist
\prgNewFunction \RowMax {m} {%
\prgReturn {\fpEval {max(#1)}}
}
\prgNewFunction \RowMin {m} {%
\prgReturn {\fpEval {min(#1)}}
}
\prgNewFunction \DrawDataBar { m m } {%
\tlClear \gTikzPathsTl%
\intStepOneInline {#1} {\arabic{rowcount}} {%
\clistSet \lCurrentRowDataClist {}
\intStepOneInline {#2} {\arabic{colcount}} {%
\clistPutRight \lCurrentRowDataClist {\cellGetText {##1} {####1} }
}
\intStepOneInline {#2} {\arabic{colcount}} {%
\fpSet \lTmpaFp {\RowMax{\expValue \lCurrentRowDataClist}}
\fpSet \lTmpbFp {\RowMin{\expValue \lCurrentRowDataClist}}
\fpSet \lTmpcFp {\cellGetText {##1} {####1} }
\fpSet \lTmpiFp {%
\fpMathDiv {\fpUse \lTmpcFp} {\fpUse \lTmpaFp}
}%
\fpSet \lTmpjFp {%
\fpMathDiv {\fpUse \lTmpcFp} {\fpUse \lTmpbFp}
}%
\fpCompareTF {\lTmpaFp} > {\cZeroFp}{
\tlPutRight \gTikzPathsTlpositive {%
\evalWhole {%
([shift={(.5pt,.5pt)}]##1-####1.south~west) rectangle
([shift={(-.5pt,-.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmpiFp}!(##1-####1.north~east)$)
}%
}%
}{%
\tlPutRight \gTikzPathsTlnegative {%
\evalWhole {%
([shift={(-.5pt,-.5pt)}]##1-####1.north~east) rectangle
([shift={(.5pt,.5pt)}]$(##1-####1.south~east)!{\fpUse \lTmpjFp}!(##1-####1.south~west)$)
}%
}%
}
}
}
}
\IgnoreSpacesOff
\begin{document}
\begin{tblrtikzbelow}
\fill [violet!80] \gTikzPathsTlpositive;
\fill [magenta!80] \gTikzPathsTlnegative;
\end{tblrtikzbelow}
\begin{tblr}{
colspec={*{5}{Q[c,3cm]}},
hlines, vlines,
row{1} = {bg=lightgray},
process=\DrawDataBar{2}{1}
}
Item1 & Item2 & Item3 & Item4 & Item5 \\
1 & 2 & 3 & 4 & 5 \\
6.5 & 5.4 & 4.3 & 3.2 & 2.1 \\
-1 & -2 & -3 & -4 & -5 \\
-6.5 & -5.4 & -4.3 & -3.2 & -2.1 \\
0.5 & 1.5 & 2.5 & 3.5 & 4.5 \\
-0.5 & -1.5 & -2.5 & -3.5 & -4.5 \\
-5.5 & -6.5 & -7.5 & -8.5 & -9.5 \\
-3.1 & -2.1 & -1.1 & -0.1 & -1.1 \\
1 & 4 & 2 & 8 & 5 \\
5.5 & 6.5 & 7.5 & 8.5 & 9.5 \\
\end{tblr}
\end{document}
由于我没想好关于「同一行内既有正数也有负数」应该如何绘制,因此\fpCompareTF的判断应该也有一定的修改空间...目前只支持全正/全负的同一行数字,且个人认为用户接口并不太友好...
增加了对于行内数字有正有负形式的支持:
\documentclass{article}
\usepackage{libertinus-otf}
\usepackage[landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{functional, tikz}
\IgnoreSpacesOn
\tlNew \gTikzPathsTlpositive
\tlNew \gTikzPathsTlnegative
\tlNew \gTikzPathsTlcrosspositive
\tlNew \gTikzPathsTlcrossnegative
\clistNew \lCurrentRowDataClist
\prgNewFunction \RowMax {m} {%
\prgReturn {\fpEval {max(#1)}}
}
\prgNewFunction \RowMin {m} {%
\prgReturn {\fpEval {min(#1)}}
}
\prgNewFunction \DrawDataBar { m m } {%
\tlClear \gTikzPathsTl%
\intStepOneInline {#1} {\arabic{rowcount}} {%
\clistSet \lCurrentRowDataClist {}
\intStepOneInline {#2} {\arabic{colcount}} {%
\clistPutRight \lCurrentRowDataClist {\cellGetText {##1} {####1} }
}
\intStepOneInline {#2} {\arabic{colcount}} {%
\fpSet \lTmpaFp {\RowMax{\expValue \lCurrentRowDataClist}}
\fpSet \lTmpbFp {\RowMin{\expValue \lCurrentRowDataClist}}
\fpSet \lTmpcFp {\cellGetText {##1} {####1} }
\fpSet \lTmpiFp {%
\fpMathDiv {\fpUse \lTmpcFp} {\fpUse \lTmpaFp}
}%
\fpSet \lTmpjFp {%
\fpMathDiv {\fpUse \lTmpcFp} {\fpUse \lTmpbFp}
}%
\fpSet \lTmpkFp {%
\fpEval {( 0 - \fpUse \lTmpbFp) / (\fpUse \lTmpaFp - \fpUse \lTmpbFp)}
}%
\fpSet \lTmppFp {%
\fpEval {(\fpUse \lTmpcFp - \fpUse \lTmpbFp) / (\fpUse \lTmpaFp - \fpUse \lTmpbFp)}
}%
\fpCompareTF {\lTmpaFp} > {\cZeroFp}{
\fpCompareTF {\lTmpbFp} > {\cZeroFp}{%
% case1: max>0 min>0
\tlPutRight \gTikzPathsTlpositive {%
\evalWhole {%
([shift={(.5pt,.5pt)}]##1-####1.south~west) rectangle
([shift={(-.5pt,-.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmpiFp}!(##1-####1.north~east)$)
}%
}%
}{
% case2: max>0 min<0
\fpCompareTF {\lTmpcFp} < {\cZeroFp}{%
% 如果当前值比0小,则从「\lTmppFp到\lTmpkFp」
\tlPutRight \gTikzPathsTlcrossnegative {%
\evalWhole {%
([shift={(.5pt,.5pt)}]$(##1-####1.south~west)!{\fpUse \lTmppFp}!(##1-####1.south~east)$)
rectangle
([shift={(-.5pt,-.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmpkFp}!(##1-####1.north~east)$)
}
}
}{%% 如果当前值比0大,则从「\lTmpkFp到\lTmppFp」
\tlPutRight \gTikzPathsTlcrosspositive {%
\evalWhole {%
([shift={(.5pt,.5pt)}]$(##1-####1.south~west)!{\fpUse \lTmpkFp}!(##1-####1.south~east)$)
rectangle
([shift={(-.5pt,.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmppFp}!(##1-####1.north~east)$)
}
}
}
}
}{%
% case3: max<0 min<0
\tlPutRight \gTikzPathsTlnegative {%
\evalWhole {%
([shift={(-.5pt,-.5pt)}]##1-####1.north~east) rectangle
([shift={(.5pt,.5pt)}]$(##1-####1.south~east)!{\fpUse \lTmpjFp}!(##1-####1.south~west)$)
}%
}%
}
}
}
}
\IgnoreSpacesOff
\begin{document}
\begin{tblrtikzbelow}
\fill [violet!80] \gTikzPathsTlpositive;
\fill [magenta!80] \gTikzPathsTlnegative;
\fill [green!80] \gTikzPathsTlcrosspositive;
\fill [cyan!80] \gTikzPathsTlcrossnegative;
\end{tblrtikzbelow}
\begin{tblr}{
colspec={*{5}{Q[c,3cm]}},
hlines, vlines,
row{1} = {bg=lightgray},
process=\DrawDataBar{2}{1}
}
Item1 & Item2 & Item3 & Item4 & Item5 \\
0.5 & 1.5 & 2.5 & 3.5 & 4.5 \\
-1 & -2 & -3 & -4 & -5 \\
-6.5 & -5.4 & -4.3 & -3.2 & -2.1 \\
6.5 & -5.4 & 4.3 & -3.2 & 2.1 \\
-0.5 & -1.5 & -2.5 & -3.5 & -4.5 \\
-5.5 & -6.5 & -7.5 & -8.5 & -9.5 \\
-1 & 2 & -3 & 4 & -5 \\
-3.1 & -2.1 & -1.1 & 1 & -1.1 \\
1 & 4 & 2 & 8 & 5 \\
5.5 & 6.5 & 7.5 & 8.5 & 9.5 \\
\end{tblr}
\end{document}
嗯...但他目前也有缺点,似乎暂时缺少对填充的数字为「0」时的支持,同时个人觉得条件判断的逻辑写复杂了,代码仍然有很大的改进空间...
完善了条件逻辑...但好像也并不完善,优化了坐标点位的命名,补充对「0」这一边界点的支持:
\documentclass{article}
\usepackage{libertinus-otf}
\usepackage[landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{functional, tikz}
\IgnoreSpacesOn
\tlNew \gTikzPathsTlpositive
\tlNew \gTikzPathsTlnegative
\tlNew \gTikzPathsTlcrosspositive
\tlNew \gTikzPathsTlcrossnegative
\clistNew \lCurrentRowDataClist
\prgNewFunction \RowMax {m} {%
\prgReturn {\fpEval {max(#1)}}
}
\prgNewFunction \RowMin {m} {%
\prgReturn {\fpEval {min(#1)}}
}
\prgNewFunction \DrawDataBar { m m } {%
\tlClear \gTikzPathsTl%
\intStepOneInline {#1} {\arabic{rowcount}} {%
\clistSet \lCurrentRowDataClist {}
\intStepOneInline {#2} {\arabic{colcount}} {%
\clistPutRight \lCurrentRowDataClist {\cellGetText {##1} {####1} }
}
\fpSet \lTmpmaxFp {\RowMax{\expValue \lCurrentRowDataClist}}
\fpSet \lTmpminFp {\RowMin{\expValue \lCurrentRowDataClist}}
\intStepOneInline {#2} {\arabic{colcount}} {%
\fpSet \lTmpnowFp {\cellGetText {##1} {####1} }
% cond1: min>0
\fpCompareT {\lTmpminFp} > {\cZeroFp} {
\fpSet \lTmpstartFp { \cZeroFp}
\fpSet \lTmpendFp { \fpEval {( \lTmpnowFp - \cZeroFp ) / ( \lTmpmaxFp - \cZeroFp ) }}
\tlPutRight \gTikzPathsTlpositive {%
\evalWhole {%
([shift={(.5pt,.5pt)}]$(##1-####1.south~west)!{\fpUse \lTmpstartFp}!(##1-####1.south~east)$)
rectangle
([shift={(-.5pt,-.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmpendFp}!(##1-####1.north~east)$)
}
}
}
% cond2: max<0
\fpCompareT {\lTmpmaxFp} < {\cZeroFp} {
% \fpSet \lTmpstartFp {\fpEval {( \cZeroFp - \lTmpnowFp ) / ( \cZeroFp - \lTmpminFp ) }}% 好像有点不对称...
\fpSet \lTmpstartFp {\fpEval {\cOneFp - ( \lTmpnowFp - \cZeroFp ) / ( \lTmpminFp - \cZeroFp ) }}
\fpSet \lTmpendFp {\cOneFp}
\tlPutRight \gTikzPathsTlnegative {%
\evalWhole {%
([shift={(.5pt,.5pt)}]$(##1-####1.south~west)!{\fpUse \lTmpstartFp}!(##1-####1.south~east)$)
rectangle
([shift={(-.5pt,-.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmpendFp}!(##1-####1.north~east)$)
}
}
}
% cond3: min < 0 < max
\fpCompareT {\lTmpminFp} < {\cZeroFp} {
\fpCompareT {\lTmpmaxFp} > {\cZeroFp} {
%% cond3进入判断
\fpSet \lTmpzeroFp { \fpEval {( \cZeroFp - \lTmpminFp ) / ( \lTmpmaxFp - \lTmpminFp )}}
\fpSet \lTmppointFp {
\fpEval { ( \lTmpnowFp - \lTmpminFp ) / ( \lTmpmaxFp - \lTmpminFp ) }
}
\fpCompareTF {\lTmpnowFp} < {\cZeroFp} {
% 分类绘制
\tlPutRight \gTikzPathsTlcrossnegative {%
\evalWhole {%
([shift={(.5pt,.5pt)}]$(##1-####1.south~west)!{\fpUse \lTmppointFp}!(##1-####1.south~east)$)
rectangle
([shift={(-.5pt,-.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmpzeroFp}!(##1-####1.north~east)$)
}
}
} {
\tlPutRight \gTikzPathsTlcrosspositive {%
\evalWhole {%
([shift={(.5pt,.5pt)}]$(##1-####1.south~west)!{\fpUse \lTmpzeroFp}!(##1-####1.south~east)$)
rectangle
([shift={(-.5pt,-.5pt)}]$(##1-####1.north~west)!{\fpUse \lTmppointFp}!(##1-####1.north~east)$)
}
}
}
}
}
}
}
}
\IgnoreSpacesOff
\begin{document}
\begin{tblrtikzbelow}
\fill [violet!80] \gTikzPathsTlpositive;
\fill [magenta!80] \gTikzPathsTlnegative;
\fill [green!80] \gTikzPathsTlcrosspositive;
\fill [cyan!80] \gTikzPathsTlcrossnegative;
\end{tblrtikzbelow}
\begin{tblr}{
colspec={*{5}{Q[c,3cm]}},
hlines, vlines, %stretch = 0,
row{1} = {bg=lightgray,font=\bfseries\large},
process=\DrawDataBar{2}{1}
}
Item1 & Item2 & Item3 & Item4 & Item5 \\
0.5 & 1.5 & 2.5 & 3.5 & 4.5 \\
-1 & -2 & -3 & -4 & -5 \\
-6.5 & -5.4 & -4.3 & -3.2 & -2.1 \\
6.5 & -5.4 & 0 & -3.2 & 2.1 \\
-0.5 & -1.5 & -8.5 & -3.5 & -4.5 \\
-5.5 & -9.5 & -2.5 & -7.5 & -6.5\\
-1 & 2 & -3 & 4 & -5 \\
-3.1 & -2.1 & -1.1 & 1 & -1.1 \\
1 & 4 & 2 & 8 & 5 \\
5.5 & 6.5 & 7.5 & 8.5 & 9.5 \\
\end{tblr}
\end{document}
首先做题不在本提问的范围内,所以搜了下题:
在B站上面看到有些大佬们用画板来画。向请问下我们在 LaTeX 能比较容易地通过计算来画出来这些答案所对应的精确图形么?就比如下面题目中的第二问。
我更倾向于LaTeX更主要是用来「绘图」而非进行「遍历直线上的点、判断是否有交点」一类精确计算的;所以要想「画出来这些答案所对应的精确图形」,不妨 先画靶子再射箭 ,从答案入手。
问题2中对「点D」是没有任何显式限制的,所以由▲ADE确定的「点E」也是自由的,换言之,直线「BE/BN」也是自由的。考虑最后再画直线「BN」。

要绘制「大概成立的图2-1」,找个差不多的「M」点即可,此时▲FMN必定不是准确的等腰直角三角形。因此这里没必要画,略去。
M(4,0)」的图2-2的情况:\documentclass[border=5pt]{standalone}
\usepackage{tkz-base}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-5,xmax=5,ymin=-3,ymax=4]
\tkzDrawX[noticks,thick]\tkzDrawY[noticks,right=2pt,thick]
\tkzDefPoints{0/0/O,-4/0/B,4/0/C,0/4/A,0/3/F}
\tkzDrawPolygon[thick](B,C,A)
\tkzDefPoint(4,0){M}
% 这里用▲FMN为等腰直角,用利用\tkzDefPointWith[orthogonal,K=-1]实现FM顺时针旋转90度来定位N点
\tkzDefPointWith[orthogonal,K=-1](F,M)
\tkzGetPoint{N}
\tkzDrawPolygon[thick](M,N,F)
\tkzDrawLine[add=1.2 and 1.5,thick](B,N)
\tkzDefPointBy[projection= onto O--F](N)
\tkzGetPoint{P}
\tkzDrawSegment[dashed,thick](N,P)
\tkzDrawPoints(O,F,M,N,B,C,A,P)
\tkzLabelPoints[above left](O)
\tkzLabelPoints[above right](C)
\tkzLabelPoints[below](B,N,M)
\tkzLabelPoints[right](P)
\tkzLabelPoints[left](A,F)
\end{tikzpicture}
\end{document}
M(-7,0)」的图2-3的情况:\documentclass[border=5pt]{standalone}
\usepackage{tkz-base}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-8,xmax=5,ymin=-3,ymax=4]
\tkzDrawX[noticks,thick]\tkzDrawY[noticks,right=2pt,thick]
\tkzDefPoints{0/0/O,-4/0/B,4/0/C,0/4/A,0/3/F}
\tkzDrawPolygon[thick](B,C,A)
\tkzDefPoint(-7,0){M}
% 这里用▲FMN为等腰直角,用斜边FM以及\tkzDefTriangle[isosceles right]来定义等腰直角三角形确定点N
\tkzDefTriangle[isosceles right](F,M)
\tkzGetPoint{N}
\tkzDrawPolygon[thick](M,N,F)
\tkzDrawLine[add=1.2 and .5,thick](B,N)
\tkzDefPointBy[projection= onto O--F](N)
\tkzGetPoint{T}
\tkzDefPointBy[projection= onto O--B](N)
\tkzGetPoint{S}
\tkzDrawSegments[dashed,thick](N,T N,S)
\tkzDrawPoints(O,F,M,N,B,C,A,T,S)
\tkzLabelPoints[above left](O)
\tkzLabelPoints[above right](C)
\tkzLabelPoints[below](B,N,M)
\tkzLabelPoints[right](T,F)
\tkzLabelPoints[above](S)
\tkzLabelPoints[left](A)
\end{tikzpicture}
\end{document}
供参考。
不做解释了,最后一种是我认为的最佳实践
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}
\begin{equation*}
\begin{bNiceArray}{ccc}[first-row,first-col]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & 1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\Hline
\text{Row 3} & 7 & 8 & 9 \\
\end{bNiceArray}
\end{equation*}
\begin{equation*}
\begin{bNiceArray}{cc|[tikz=dashed,color=red]c}[first-row,first-col,margin]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & 1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\Hline
\text{Row 3} & 7 & 8 & 9 \\
\end{bNiceArray}
\end{equation*}
\begin{equation*}
\begin{bNiceArray}{cc|[tikz=dashed]c}[first-row,first-col,margin]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & \Block[borders={bottom,right,tikz=dashed}]{2-2}{}
1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\text{Row 3} & 7 & 8 &\Block[borders={left,top,tikz=dashed}]{1-1}{} 9 \\
\end{bNiceArray}
\end{equation*}
\begin{equation*}
\begin{bNiceArray}{cc|[tikz=dashed,color=violet]c}[first-row,first-col,margin]
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\text{Row 1} & 1 & 2 & 3 \\
\text{Row 2} & 4 & 5 & 6 \\
\Hline[tikz=dashed,color=orange]
\text{Row 3} & 7 & 8 & 9 \\
\end{bNiceArray}
\end{equation*}
\end{document}
代码要给完整,不要给别人增加负担。
\documentclass[fontset=fandol]{ctexart}
\usepackage{amsmath,amsfonts}
\usepackage{lipsum}
\begin{document}
\lipsum[1][1-3]
\begin{equation*}
\text{单品加成率} = (\text{销售单价} - \text{批发价}) / \text{批发价} \times 100\%
\end{equation*}
\lipsum[1][1-3]
\end{document}
\documentclass开始到\end{document}结束)。能够自动保持参数中的字母(a-z)为正体(即\mathrm{a}等)同时能够正确解释其他LaTeX指令(至少能够保证上下标以及\bar命令被正确解释)
但是对于\mathup吞的参数,只要没有过于神秘的希腊字母、花体字母一类的在ams框架下缺少的字体。这 似乎 是可行的。
\documentclass[fontset=fandol]{ctexart}
\usepackage{amsmath,amsfonts,amssymb}
\DeclareMathAlphabet{\mathup}{OT1}{\familydefault}{m}{n}
\begin{document}
\begin{tabular}{*{3}{c}}
\hline\hline
默认的效果 & 期望的结果 & 实际结果 \\
\hline
$p2_1/b11$ & $\mathrm{p}2_{1}/\mathrm{b}11$ & $\mathup{p2_1/b11}$ \\
\hline
$p\bar{6}m2$ & $\mathrm{p}\bar{6}\mathrm{m}2$ & $\mathup{p\bar{6}m2}$ \\
\hline
$x_1^n + \hat{y} - \sqrt{z}$ & $\mathrm{x}_1^{\mathrm{n}} + \hat{\mathrm{y}} - \sqrt{\mathrm{z}}$ & $\mathup{x_1^n + \hat{y} - \sqrt{z}}$ \\
\hline
$\sum_{n=1}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}$ & $\mathrm{\sum_{n=1}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}}$ & $\mathup{\sum_{n=1}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}}$ \\
\hline\hline
\end{tabular}
\end{document}

注意
\tkzGetAngle(angleADG)与
\tkzGetAngle{angleADG}看文档的例子:

所以,你只要把\tkzGetAngle(angleADG)替换为\tkzGetAngle{angleADG}即可
\documentclass[border=5pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
% ===== 定义点 =====
\tkzDefPoints{0/0/C, 4/0/E}
\tkzDefTriangle[two angles=23 and 37](C,E)
\tkzGetPoint{B}
\tkzDefPointBy[rotation=center B angle -90](C)
\tkzGetPoint{A}
\tkzDefPointBy[rotation=center B angle 90](E)
\tkzGetPoint{D}
\tkzCalcLength(B,D)
\tkzGetLength{BDlen}
\tkzDefPointWith[linear normed, K=\BDlen](B,A)
\tkzGetPoint{G}
\tkzFindAngle(A,D,G)
\tkzGetAngle{angleADG}%<-注意花括号
\tkzDefPointBy[rotation=center B angle \angleADG](A)
\tkzGetPoint{f}
\tkzInterLL(B,f)(A,D)
\tkzGetPoint{F}
% ===== 绘制图形 =====
\tkzDrawPolygon[thick](B,C,E)
\tkzDrawSegments[thick](A,B D,B A,C D,E A,D D,G B,F G,F)
\end{tikzpicture}
\end{document}如果只要用一次,那么也可以直接用\tkzAngleResult,这样可以不用再\tkzGetAngle多写一行...

\documentclass[border=5pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[font=\small]
% ===== 定义点 =====
\tkzDefPoints{0/0/C, 4/0/E}
\tkzDefTriangle[two angles=23 and 37](C,E)
\tkzGetPoint{B}
\tkzDefPointBy[rotation=center B angle -90](C)
\tkzGetPoint{A}
\tkzDefPointBy[rotation=center B angle 90](E)
\tkzGetPoint{D}
\tkzCalcLength(B,D)
\tkzGetLength{BDlen}
\tkzDefPointWith[linear normed, K=\BDlen](B,A)
\tkzGetPoint{G}
\tkzFindAngle(A,D,G)
% \tkzGetAngle(angleADG)
\tkzDefPointBy[rotation=center B angle \tkzAngleResult](A)
\tkzGetPoint{f}
\tkzInterLL(B,f)(A,D)
\tkzGetPoint{F}
% ===== 绘制图形 =====
\tkzDrawPolygon[thick](B,C,E)
\tkzDrawSegments[thick](A,B D,B A,C D,E A,D D,G B,F G,F)
\end{tikzpicture}
\end{document}
问 用\cite 生成超链接“[1]”时,只有里面的1可点击,能否让整个“[1]”点击跳转呢?