鱼香肉丝没有鱼先生
鱼香肉丝没有鱼先生
脾气不好,别来惹我!!!

注册于 4年前

回答
108
文章
1
关注者
8

测试没有问, 请提供 mwe

\documentclass{article}
\usepackage{codehigh}
\usepackage[margin=1cm]{geometry}
\begin{document}
\makeatletter
\begin{demohigh}
 %\makeatletter
\def\@cmd[#1]#2{\textcolor{red}{#1} and (#2)}
\def\cmd{
  \@ifnextchar[{\@cmd}{\@cmd[default]}
}
\cmd{aaa}\par 
\cmd[bbb]{aaa}\par 

\def\@cmd[#1]#2{\c@md{} and \textcolor{red}{#1} and (#2)}
\def\cmd#1{
  \def\c@md{#1}\@ifnextchar[{\@cmd}{\@cmd[default]}
}
\cmd{aaa}{ccc}\par 
\cmd{aaa}[bbb]{ccc}    
 %\makeatother  

\end{demohigh}
\makeatother
\end{document}

编译环境
win11 + texlive2022 + xelatex && pdflatex
ASD.png

  • \def\@dnode[#1]#2#3#4{\node(#2)at(#3){#4};} 的问题,#1 没有传进去,改为

\def\@dnode[#1]#2#3#4{\node[#1](#2)at(#3){#4};}

  • LaTeX2e 提供了 \newcommand 命令可以定义一个带可选参数的命令,此外可以看看 xparse 宏包,其基于 LaTeX3 更加灵活
\makeatletter
\def\@dnode[#1]#2#3#4{\node[#1](#2)at(#3){#4};}
\def\dnode{\@ifnextchar[{\@dnode}{\@dnode[inner sep=2pt,fill=yellow]}}
\makeatother

\begin{tikzpicture}
  \dnode{a}{1,2}{\LaTeX}
  \dnode[draw,fill=red]{b}{3,2}{hello!}
\end{tikzpicture}

典型宏展开问题
报错信息如下

Package pgfkeys: I do not know the key '/tikz/\inns {2}' and I am going to ignore it. Perhaps you misspelled it.

也就是说 tikz\inns{2}(还没展开成 inner sep=2pt) 当作了键值, 但是它无法识别,为此我们必须改变 \node\inns 两个命令的展开顺序,做如下修改

  • 不使用 \NewDocumentCommand 来定义要展开的命令,使用 \def 或者 \newcommand
\newcommand{\inns}[1]{inner sep=#1pt} 
  • 改变宏展开顺序
\expandafter\node\expandafter[\inns{2}](b)at(1,0){B};

mwe

\documentclass{article}
\usepackage{tikz}
\begin{document}
\NewDocumentCommand\tik{m}{
\begin{tikzpicture}
#1
\end{tikzpicture}
}
\newcommand{\inns}[1]{inner sep=#1pt}

\tik{
\node(a)at(0,0){A};
\expandafter\node\expandafter[\inns{2}](b)at(1,0){B};
\draw(a)--(b);
}
\end{document}

另外 \NewDocumentCommand 命令定义的命令是受保护的,但是 xparse 包也提供了 \NewExpandableDocumentCommand,但经过测试失败,不知为何

简单回答一下

  • pgf/TiKZ 中有两个尺寸寄存器 \pgf@x \pgf@y 分别用于保存当前的坐标,(类似你的 \pgfgetlastxy)但是“很遗憾”,他们的单位都是 pt,如:
\makeatletter
\begin{tikzpicture}
\path (1,1);
\node[above right] at (1,1) {(\the\pgf@x,\the\pgf@y)};
\end{tikzpicture}
\makeatother

得到
QQ截图20220728222852.png

为此你需要将其转化为 cm, 可以定义一个命令

\def\pttocm#1{\pgfmathparse{#1/28.45274}\pgfmathresult}

pt 转化为 cm
一个完整的 mwe:

\documentclass{article}
\usepackage{tikz} 

\begin{document}
\def\pttocm#1{\pgfmathparse{#1/28.45274}\pgfmathresult}
\makeatletter
\begin{tikzpicture}
\path (1,1);
\node[above right] at (1,1) {(\pttocm{\the\pgf@x},\pttocm{\the\pgf@y})};
\end{tikzpicture}
\makeatother
\end{document}

QQ截图20220728223513.png

  • 此外,你的提问习惯不太好,希望你提问能够好好理解 mwe 一词,不然一大堆代码,没那么多人愿意帮你分析(个人观点)

tikz 画了一下,可以自己搬到 tcolorbox 里面

\documentclass[margin=.5cm]{standalone}
\usepackage{tikz,ctex}
\usepackage{fontawesome5}
\usetikzlibrary{arrows.meta,calc}

\begin{document}

\begin{tikzpicture}[thick]
\draw[] (0.4,0) arc(0:90:0.4) -- (0,1.6) arc(-90:0:0.4) --(5.6,2) arc(180:270:0.4) --(6,0.4) arc(90:180:0.4) --cycle;


\foreach \x in {(45:0.382),($(0,2)+(-45:0.382)$),($(6,2)+(225:0.382)$),($(6,0)+(135:0.382)$)}
{
  \node[inner sep=0pt,] at \x 
  {
   \begin{tikzpicture}
    \draw[fill=white,thick,rotate=45,line join=round,x=0.12cm,y=0.12cm] (1,0) to [out=180,in=-90] (0,1) to [out=-90,in=0] (-1,0) to[out=0,in=90] (0,-1) to[out=90,in=180] (1,0)--cycle;
   \end{tikzpicture}
  };
}

\draw[] (0.3,0.075) -| (0.075,0.3);
\draw[] (0.075,1.7) |- (0.3,2-0.075);
\draw[] (5.7,2-0.075) -| (6-0.075,1.7);
\draw[] (6-0.075,0.3) |- (5.7,0.075);

\draw[] (0.075,0.5) -- (0.075,1.5);
\draw[] (0.5,2-0.075) -- (5.5,2-0.075);
\draw[] (6-0.075,1.5) -- (6-0.075,0.5);
\draw[] (5.5,0.075) -- (0.5,0.075);


\node[font=\kaishu\bfseries] at (3,1.1) {奈何蝶飞去};
\node[font=\kaishu\bfseries,scale=0.6] at (3,1.5) {引蝶之章 第一幕};
\draw[line cap=round] (2,0.8) -- (4,0.8)node[midway,fill=white,inner sep=2pt,scale=0.6]{\faGg};

\node[font=\kaishu\bfseries,scale=0.6] at (3,0.45){已开启};
\end{tikzpicture}

\end{document}

QQ截图20220727100628.png

另外,楼上@u40 啸行的答案很有参考性!!!

\begin{tikzpicture}
  \node[] (a) {$x$};
  \draw[->] (a.north) to[out=135,in=90] ([xshift=-0.2cm]a.west) to[out=-90,in=-135] (a.south);
\end{tikzpicture}

QQ截图20220726193530.png

\begin{tikzpicture}
  \node[inner sep=1pt] (a) at (0,0) {$x$};
  \node[inner sep=1pt] (b) at (2,2) {$y$};
  \draw[-latex] (a.0) -- (b.-90);
  \draw[-latex] (a.90) to[out = 90,in=180]  (b.180);
\end{tikzpicture}

QQ截图20220726215319.png

提供一种思路

使用 magicwatermark 宏包, 并通过外部文件来添加页脚信息.

%pagefoot.txt
{faraday.jpg}{爱情既是友谊的代名词,又是我们为共同的事业而奋斗的可靠保证,爱情是人生的良伴,你和心爱的女子同床共眠是因为共同的理想把两颗心紧紧系在一起。\par \hfill ------ 法拉第}
{newton.jpg}{苹果砸了我的头,我成了物理学家。\par \hfill ------ 牛顿}
%main.tex
\documentclass{ctexart}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\graphicspath{{figure/}}
\usepackage{fontawesome5}
\usepackage{magicwatermark}
\usepackage{zhlipsum}

\ExplSyntaxOn
\clist_clear_new:N \l_pagefoot_image_clist 
\clist_clear_new:N \l_pagefoot_text_clist

\cs_new:Npn \pagefoot_add_content:nn #1#2 {
  \clist_gput_right:Nn \l_pagefoot_image_clist { #1 }
  \clist_gput_right:Nn \l_pagefoot_text_clist { #2 }
}
\ior_open:Nn \g_tmpa_ior { pagefoot.txt }
\ior_map_inline:Nn \g_tmpa_ior 
{
  \pagefoot_add_content:nn #1
}
\ior_close:N \g_tmpa_ior

\PageSetup*{
  \begin{tikzpicture}[remember~picture,overlay]
    \fill[red!25] ([xshift=1cm]current~page.south~west) rectangle ([yshift=3cm]current~page.south~east);
    \fill[red!50] ([xshift=1cm,yshift=1cm]current~page.south~west) --++(0,2) -- ++(2,0)--cycle;
    \fill[red!50] ([xshift=-2cm]current~page.south~east) -- ++(2,0) -- ++(0,2)--cycle;
    \node[anchor=west] at ([shift={(1.2,1.5)}]current~page.south~west){\includegraphics[width=1.8cm,height=2.4cm]{\clist_item:Nn \l_pagefoot_image_clist{ \thepage }}};
    \node[font=\bfseries,] at ([shift={(-0.5,0.5)}]current~page.south~east){\thepage};
    \node[anchor=north~west] at ([shift={(3.5,2.8)}]current~page.south~west)
    {
      \begin{minipage}{\dimeval{\paperwidth-4.5cm}}
        \textcolor{red!50}{\faBook}\hskip .5em\tikz[baseline]{\node[anchor=base,rounded~corners,fill=red!50,inner~sep=.3mm]{物理学史};}\hskip 1em  \clist_item:Nn \l_pagefoot_text_clist { \thepage }
      \end{minipage}
    };
  \end{tikzpicture}
}
\ExplSyntaxOff
\Watermark
\pagestyle{empty}
\begin{document}
\zhlipsum[1]
\newpage
\zhlipsum[2]
\end{document}

效果如下:
第一页
1.png
第二页
2.png

附件:
pagefoot.zip

给一个较为简单的办法:
定义函数 \tzhmode 如下

\NewDocumentCommand{\tzhmode}{m}
{
  \str_case:nn {#1} 
  {
    {show}
    {
    \def\xsbxd{
      \int_step_inline:nnn{1}{3}{
      \noindent \seq_item:Nn \xsb_jianda{####1}\par
      \noindent \seq_item:Nn \xsb_xiangda{####1}\par
      }
    }
    }
    {hide}{\let\xsbxd\relax}
  }
}

再为 \enddocument 添加一个 hook,

\AtEndDocument
{
  \newpage
  \xsbxd
}  

即可.
完整 mwe 如下:

\documentclass{ctexart}
\ExplSyntaxOn

\seq_new:N \xsb_jianda
\seq_new:N \xsb_xiangda
\tl_new:N \c_teacher_mode_tl
\tl_set:Nn \c_teacher_mode_tl{详答}
\tl_new:N \c_printer_mode_tl
\tl_set:Nn \c_printer_mode_tl{简答}

\tl_new:N \g__tzhmode_tl

\NewDocumentCommand{\tzhmode}{m}
{
  \str_case:nn {#1} 
  {
    {show}
    {
    \def\xsbxd{
      \int_step_inline:nnn{1}{3}{
      \noindent \seq_item:Nn \xsb_jianda{####1}\par
      \noindent \seq_item:Nn \xsb_xiangda{####1}\par
      }
    }
    }
    {hide}{\let\xsbxd\relax}
  }
}



%创建解答环境
\NewDocumentEnvironment{solution}{s +b} %\begin{solution}*    \end{solution}       \begin{solution}         \end{solution}
{
  \tl_if_eq:NNTF \g_tzhmode_tl \c_teacher_mode_tl
  {
    \par
    \IfBooleanTF{#1}
    {
        ~#2
    }
    {
        ~#2
    }
  }{}
  \seq_gput_right:Nn \xsb_xiangda{#2 \par}
}
{

}

%创建答案命令
\NewDocumentCommand{\daan}{o +m}{
  \par
  \tl_if_eq:NNTF \g_tzhmode_tl \c_printer_mode_tl
  {
    \IfNoValueTF{#1}{~#2 \par }{~#2 \hspace{1cm} ~#1 \par }
  }
  {
    \tl_if_eq:NNT \g_tzhmode_tl \c_teacher_mode_tl
    {
      \IfNoValueTF{#1}{~#2 \par }{~#2 \hspace{1cm} ~#1 \par }
    }
  }
  \seq_gput_right:Nn \xsb_jianda{#2}
}


\NewDocumentCommand{\xsbjd}{}
{
  \seq_map_inline:Nn \xsb_jianda{##1}
}

\AtEndDocument
{
  \newpage
  \xsbxd
}  

\ExplSyntaxOff

\begin{document}
      \tzhmode{show}
    % \tzhmode{hide}
    \begin{enumerate}
        \item 这是第一题
        \daan{选A}
        \begin{solution}
            为什么选择A
        \end{solution}
        \item 这是第二题
        \daan{选B}
        \begin{solution}
            为什么选择B
        \end{solution}
        \item 这是第三题
        \daan{选C}
        \begin{solution}
            为什么选择C
        \end{solution}
    \end{enumerate}
\end{document}

请提供最小工作示例

使用 \node[] at (2,2) {$y=(x+1)-\frac{1}{3}e^x$}; 标注即可

有没有觉得你的需求有些奇怪)
在固定的盒子里面,你想放一个“漂浮”的物体(

好久没画图了,手生,将就一下吧

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,arrows.meta}
\begin{document}
\begin{tikzpicture}[>=Stealth]
  \draw[->] (-3,0) -- (3,0);
  \foreach \x in{20,30,40}
  \draw[->,name path=p\x] (0,0) -- (\x:3);
  \draw[name path=p50,domain=-2:2,smooth] plot (\x,0.5*\x*\x);
  \draw[name intersections={of=p20 and p50,name=i,total=\t},fill=white]
  {(i-2) circle (1pt)}; 
  \draw[name intersections={of=p30 and p50,name=i,total=\t},fill=white]
  {(i-2) circle (1pt)}; 
  \draw[name intersections={of=p40 and p50,name=i,total=\t},fill=white]
  {(i-2) circle (1pt)}; 
  \draw[name intersections={of=p20 and p50,name=i,total=\t},fill=white]
  {(i-1) circle (1pt)}; 
\end{tikzpicture}
\end{document}

QQ截图20220611112830.png

tex的计算能力有限,使用 l3fp 帮助计算

讨论见此 tikz用plot画图象报错dimension too large

另外需要加上 xmax=1e4 选项才能显示完整.

\documentclass[1pt]{standalone}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{euler}
%\usepackage{MnSymbol}
%\usepackage{stmaryrd}
\usepackage{xcolor}
%use xfp package
\usepackage{xfp}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{colormaps}
\usetikzlibrary{pgfplots.groupplots,matrix}
\pgfplotsset{height=8cm,width=8cm}
\begin{document}
\begin{tikzpicture}
    \begin{loglogaxis}[
        enlargelimits=false,
        grid=both,
        ymin=5e-6,ymax=1,
        xmax=1e4,
        ymode=normal,
        xlabel= undulations per revolution(UPR),
        ylabel=amplitude transmission,
        log basis y=10,
        log basis x=10,
        domain=1e0:1e4,samples=60,smooth,
        ]
        % use \fpeval with xfp, x --> \x 
        \addplot+[no marks,ultra thick,black]{\fpeval{exp(((0.4697*1/15*\x)^2)*(-3.1415))}}; 
        \addplot+[no marks,ultra thick,black]{\fpeval{exp(((0.4697*1.25/50*\x)^2)*(-3.1415))}};
        \addplot+[no marks,ultra thick,black]{\fpeval{exp(((0.4697*1.5/150*\x)^2)*(-3.1415))}};
        \addplot+[no marks,ultra thick,black]{\fpeval{exp(((0.4697*1.75/500*\x)^2)*(-3.1415))}};
        \addplot+[no marks,ultra thick,red,opacity=0.8]{exp(((0.4697*2/1500*x)^2)*(-3.1415))};
    \end{loglogaxis}
\end{tikzpicture}
\end{document} 

3.png

函数拟合,不太好想

Bézier 凑合凑合

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \draw[-latex] (-2,0) -- (2,0)node[right]{$x$};
    \draw[-latex] (0,-1.8) -- (0,1.8)node[above]{$y$};
    \draw[rounded corners] (0,0) ..controls (0.19,0.2) .. (0.4,1) ..controls(1.13,0.58).. (1.7,0)node[below]{$\pi$};
    \draw[rounded corners] (0,0) ..controls (-0.19,0.2) .. (-0.4,1) ..controls(-1.13,0.58).. (-1.7,0)node[below]{$-\pi$};
  \end{tikzpicture}
\end{document}

1.png

分开关都做好了不会做总开关,加一个不就可以了吗

\documentclass{ctexart}
\usepackage{xparse}
\newif\ifprint
\newcommand{\tk}[1]{\underline{
\ifprint
#1
\else
\hspace*{5em}
\fi}}
\newif\ifzhengming
\NewDocumentEnvironment{zhengming}{ +b }{
\ifzhengming
\par
{\bfseries 证明}\, #1
\else
{\vspace{3cm}}
\fi
}{\par}

\newif\ifshowanswer
\showanswertrue %看这里
\ifshowanswer
\printtrue
\zhengmingtrue
\else
\printfalse
\zhengmingfalse
\fi 
\begin{document}

填空题\tk{答案}

解答题
\begin{zhengming}
这是证明
\end{zhengming}

\end{document}

  • 很抱歉,我不熟悉 xkeyval 包的使用方法,短时间内我不愿意花时间去阅读这个包
  • 我将以 l3keys 为您演示,给您提供另一个方案

testclass.cls

\ProvidesClass{testclass}
\NeedsTeXFormat{LaTeX2e}

\RequirePackage{l3keys2e}
\ExplSyntaxOn
%定义 keyval,第一个参数为模块名,第二个参数为所要设置的 keyval 列表
\keys_define:nn{family} 
{
  name.tl_set:N = \l_name_tl,
  age.int_set:N = \l_age_int,
}


\def\myname{\textbf{\tl_use:N \l_name_tl}}
\def\myage{\textbf{\int_use:N \l_age_int}} 
% 设置默认值
\keys_set:nn{family}
{
  name = ljguo,
  age  = 21,
}
\ExplSyntaxOff
% 传递 family 模块的 keyval list 给 class
\ProcessKeysOptions{family}
\LoadClass{ctexbook}

main.tex

\documentclass{testclass}
\begin{document}
my name is \myname, and i am \myage ~years old.
\end{document}

这将得到:
2.png

\documentclass[name = zhangsan,age = 81]{testclass}
\begin{document}
my name is \myname, and i am \myage ~years old.
\end{document}

这将得到:
1.png

  • 请使用 texdoc interface3 了解更详细的用法

发布
问题