Sagittarius Rover
Sagittarius Rover
这家伙很懒,什么也没写!

注册于 3年前

回答
442
文章
0
关注者
15

LaTeX插入.eps图片的逻辑是:

  • 内部使用epstopdf.exe先将.eps转为.pdf
  • 然后按照正常插入.pdf的方法实现

从报错信息来看:

Package pdftex.def: File `1-eps-converted-to.pdf' not found: using draft setting.

可能你需要检查一下在wslepstopdf程序是否存在,是否可以直接运行.

一个基于stackengine的方案为:

\documentclass{article}
\usepackage{centernot}
\usepackage{stackengine}
\usepackage{amsmath,amssymb}
\newcommand*{\notLongrightarrow}{\centernot{\Longrightarrow}}
\newcommand*{\notLongleftarrow}{\centernot{\Longleftarrow}}
\newcommand*{\onlyRtoL}[1][-2pt]{\mathrel{\stackanchor[#1]{$\Longleftarrow$}{$\notLongrightarrow$}}}
\begin{document}

\[A \Longrightarrow B \notLongrightarrow C\]

\[A \Longleftarrow B \notLongleftarrow C\]

\[A \mathrel{\stackanchor{$\Longleftarrow$}{$\Longrightarrow$}} B \]

\[A \mathrel{\stackanchor[4pt]{$\notLongleftarrow$}{$\Longrightarrow$}} B \]

\[ 
\lim_{n\to\infty} y_n \quad \onlyRtoL[5pt] \quad |y_1|+|y_2|+\cdots+|y_n|\leq M\]

\end{document}

image.png

这是普通的行间距。对于中文,会被ctex通过默认的scheme=chinese设置为1.3倍...

如果你确实希望缩短全文的中文行距,可以用:scheme=plain...

image.png

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

image.png

\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}

image.png


Edited:中西文对比

\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}

image.png

Edited Again:

\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}

image.png

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}

image.png


哇...根源貌似找到了: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}

image.png

此时对于正文段落的间距\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}

image.png

沉默...


把评论区中的测试代码搬到我们的目标「希望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}

image.png

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


version 1

\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}

image.png

version 2

\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}

image.png

不要重复提问。

请删除另一个问题。

你可以@超管 @u30 查看。

可以试试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} 

image.png

不知道效果对不对...

image.png

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

image.png

你可以试试「只有法语文档」的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}

image.png

想要随心所欲地绘制切线,参考nidarfp的回答


\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}

image.png

Thanks to Jasper Habicht!


最初的尝试 version1

一个可能的答案如下:

\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}

image.png

由于我没想好关于「同一行内既有正数也有负数」应该如何绘制,因此\fpCompareTF的判断应该也有一定的修改空间...目前只支持全正/全负的同一行数字,且个人认为用户接口并不太友好...


Edit: 直接增加功能version2

增加了对于行内数字有正有负形式的支持:

\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}

image.png

嗯...但他目前也有缺点,似乎暂时缺少对填充的数字为「0」时的支持,同时个人觉得条件判断的逻辑写复杂了,代码仍然有很大的改进空间...

Re-Edit:version3

完善了条件逻辑...但好像也并不完善,优化了坐标点位的命名,补充对「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}

image.png

搜题找到答案

首先做题不在本提问的范围内,所以搜了下题:

搜题答案.pdf

在B站上面看到有些大佬们用画板来画。向请问下我们在 LaTeX 能比较容易地通过计算来画出来这些答案所对应的精确图形么?就比如下面题目中的第二问。

我更倾向于LaTeX更主要是用来「绘图」而非进行「遍历直线上的点、判断是否有交点」一类精确计算的;所以要想「画出来这些答案所对应的精确图形」,不妨 先画靶子再射箭 ,从答案入手。

问题2中对「点D」是没有任何显式限制的,所以由▲ADE确定的「点E」也是自由的,换言之,直线「BE/BN」也是自由的。考虑最后再画直线「BN」。

答案中有三个相关的可能情况,需要一一做排除

image.png

情况一:不存在这样的三角形,进而不存在「精确图形」

要绘制「大概成立的图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}

image.png

情况三:考虑当「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}

image.png

供参考。

不做解释了,最后一种是我认为的最佳实践

\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}

image.png

代码要给完整,不要给别人增加负担。

\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}

image.png

  1. 请提供完整的可编译代码(从\documentclass开始到\end{document}结束)。
  2. 请补充当前代码的编译效果截图。如果有错误,请贴报错信息。
  3. 提供一个预期效果图示,仅有「排版图片 排版格式问题 图片」几个字谁能弄明白呢,并解释上面的「Excel页面」和「图表」具体是什么,与你的问题有何关系。

发布
问题