带有 TikZ 或图片的 Insbox

带有 TikZ 或图片的 Insbox

因此,使用s、es 甚至纯文本都input{insbox}可以正常工作。但是,使用s 或s 与s 不兼容。equationtcolorboxtikzpicturefiguretikzpicture

  1. 我尝试过figure包含tikzpicture
\InsertBoxL{0}{
    \begin{figure}
    \centering
    \begin{tikzpicture}[x=.25in,y=.25in]

        \draw [<-, thick] (0, 4.2) coordinate (Yin) node [above] {$y$}
                       -- (0, 0.0)
                       -- (0,-1.2) coordinate (Yout);
        \draw [->, thick] (-1.5,0) coordinate (Xin)
                       -- ( 0.0,0)
                       -- ( 4.5,0) coordinate (Xout) node [right] {$x$};

        \draw [thick] (2.8, 0.9) -- (1.8, 0.9) node [midway,below] {$\Delta x$};
        \draw [thick] (2.8, 0.9) -- (2.8, 1.4) node [midway,right] {$\Delta y$};

        \draw [domain=-1:4,variable=\x,red,thick] plot({\x},{(\x)/2});

    \end{tikzpicture}
  % \caption{Linear function}
    \label{fig:linear}
    \end{figure}
}
  1. 只是一个tikzpicture
\InsertBoxL{0}{
    \begin{tikzpicture}[x=.25in,y=.25in]

        \draw [<-, thick] (0, 4.2) coordinate (Yin) node [above] {$y$}
                       -- (0, 0.0)
                       -- (0,-1.2) coordinate (Yout);
        \draw [->, thick] (-1.5,0) coordinate (Xin)
                       -- ( 0.0,0)
                       -- ( 4.5,0) coordinate (Xout) node [right] {$x$};

        \draw [thick] (2.8, 0.9) -- (1.8, 0.9) node [midway,below] {$\Delta x$};
        \draw [thick] (2.8, 0.9) -- (2.8, 1.4) node [midway,right] {$\Delta y$};

        \draw [domain=-1:4,variable=\x,red,thick] plot({\x},{(\x)/2});

    \end{tikzpicture}
}
  1. 它甚至无法处理内部的纯文本figure
\InsertBoxL{0}{
    \begin{figure}What does NOT seem to work is this\end{figure}
}

Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here.

使用纯文本的 MWE作品:

\documentclass[a5paper,12pt,twoside,openany]{memoir}
\usepackage[a5paper]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\input{insbox}

\begin{document}

\InsertBoxL{0}{
    \textbf{What does seem to work is this}
}

Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. Text goes here. 

\end{document}

MWETikZfigure没有工作:

\documentclass[a5paper,12pt,twoside,openany]{memoir}
\usepackage[a5paper]{geometry}
\usepackage{tikz}

\input{insbox}

\begin{document}

\InsertBoxL{0}{
    \begin{figure}
    \centering
    \begin{tikzpicture}[x=.25in,y=.25in]

        \draw [<-, thick] (0, 4.2) coordinate (Yin) node [above] {$y$}
                       -- (0, 0.0)
                       -- (0,-1.2) coordinate (Yout);
        \draw [->, thick] (-1.5,0) coordinate (Xin)
                       -- ( 0.0,0)
                       -- ( 4.5,0) coordinate (Xout) node [right] {$x$};

        \draw [thick] (2.8, 0.9) -- (1.8, 0.9) node [midway,below] {$\Delta x$};
        \draw [thick] (2.8, 0.9) -- (2.8, 1.4) node [midway,right] {$\Delta y$};

        \draw [domain=-1:4,variable=\x,red,thick] plot({\x},{(\x)/2});

    \end{tikzpicture}
  % \caption{Linear function}
    \label{fig:linear}
    \end{figure}
}

\end{document}

编辑:这似乎与所包含的序言有关……

我尝试删除我的序言,当然,完整文档被搞砸了,但盒子似乎终于能正常工作了。有人能发现下面序言中有什么会干扰宏吗insbox

\usepackage{tocloft}
\usepackage{hyperref}
\usepackage{emptypage}
\usepackage[inline]{enumitem}
\usepackage[export]{adjustbox}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage[usenames,dvipnames,table]{xcolor}

\usepackage{bm,amsmath,amssymb,amsthm,gensymb,esdiff,siunitx}
%===========================================================
%///////////////////////////////////////////////////////////

% Universal command to recognise environments:

\makeatletter

\def\ifenv#1{
   \def\@tempa{#1}%
   \ifx\@tempa\@currenvir
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
   \fi
}

\makeatother

\usepackage{xparse}

%%% \usepackage{xparse}
%%% 
%%% \ExplSyntaxOn
%%% \NewDocumentCommand{\newenvcommand}{ m m } % #1 = env name, #2 = command name
%%% {
%%%     \tl_if_exist:cF { g_envc_#1_list_tl } { \tl_new:c { g_envc_#1_list_tl } }
%%%     \tl_gput_right:cn { g_envc_#1_list_tl } { #2 }
%%%     \exp_args:Nc \newcommand { w envc_#1_\cs_to_str:N #2 }
%%% }
%%% \NewDocumentCommand{\checkenvcommands}{ }
%%% {
%%%     \tl_if_exist:cT { g_envc_\use:c {@currenvir} _list_tl }
%%%     {
%%%         \tl_map_inline:cn { g_envc_\use:c {@currenvir} _list_tl }
%%%         {
%%%             \cs_set_eq:Nc ##1 { envc_\use:c {@currenvir} _\cs_to_str:N ##1 }
%%%         }
%%%     }
%%% }
%%% \ExplSyntaxOff

\ExplSyntaxOn
\NewDocumentCommand{\newenvcommand}{ m m } % #1 = env name, #2 = command name
  {
   \cs_if_exist:cF { g_envc_#1_list_tl } { \tl_new:c { g_envc_#1_list_tl } }
   \tl_gput_right:cn { g_envc_#1_list_tl } { #2 }
   \exp_after:wN \newcommand \cs:w envc_#1_\cs_to_str:N #2 \cs_end:
   % { Removing this line will cause Overleaf to make trouble }
  } 
\NewDocumentCommand{\checkenvcommands}{ }
  {
   \cs_if_exist:cT { g_envc_\use:c {@currenvir} _list_tl }
     {
      \tl_map_inline:cn { g_envc_\use:c {@currenvir} _list_tl }
        { \cs_set_eq:Nc ##1 { envc_\use:c {@currenvir} _\cs_to_str:N ##1 } }
     }
  }
\ExplSyntaxOff

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Underlines:

\usepackage{ulem}
\usepackage{contour}

\renewcommand{\ULdepth}{1.8pt}
\contourlength{0.8pt}

\newcommand{\ul}[1]{%
  \uline{\phantom{#1}}%
  \llap{\contour{white}{#1}}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Boxes:

\usepackage{empheq}
\usepackage[many]{tcolorbox}

\tcbset{enhanced,boxrule=0.8pt,bottomrule=1.6pt,arc=0pt,auto outer arc,lifted shadow={1mm}{-1mm}{2mm}{0.1mm}{gray!60}}
\newtcbox{\eqbox}[3][]{nobeforeafter,math upper,colback=#2,colframe=#3,#1}
\newtcbox{\ndbox}[3][]{nobeforeafter,math upper,colback=#2,colframe=#3,#1}

\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{highlight/.style args={#1}{fill=#1,rounded corners=1.6pt,inner xsep=1ex,minimum height=1.5em},
%copy shadow={shadow xshift=0pt,shadow yshift=-0.4pt},
mylight/.style={highlight={red!30!yellow!40}{black!30!red!30!yellow}}}

%%% \usepackage{framed}
%%% \usepackage[nodisplayskipstretch]{setspace}
%%% 
%%% \definecolor{shadecolor}{rgb}{.827451,.827451,.827451}
%%% 
%%% \setlength{\OuterFrameSep}{0pt}

%---------------------------------
\newenvcommand{tcolorbox}{\ul}[1]{%
  \uline{\phantom{#1}}%
  \llap{\contour{shadecolor}{#1}}%
}
%---------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Tables:

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{array}

%\newcommand\undefcolumntype[1]{\expandafter\let\csname NC@find@#1\endcsname\relax}
%\newcommand\forcenewcolumntype[1]{\undefcolumntype{#1}\newcolumntype{#1}}

%\newcolumntype{P}{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}X}
%\newcolumntype{D}{>{\centering  \let\newline\\\arraybackslash\hspace{0pt}}X}
%\newcolumntype{Q}{>{\raggedleft \let\newline\\\arraybackslash\hspace{0pt}}X}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering  \let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft \let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

\newcolumntype{F}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{M}[1]{>{\centering  \let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{E}[1]{>{\raggedleft \let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newcolumntype{P}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}b{#1}}
\newcolumntype{B}[1]{>{\centering  \let\newline\\\arraybackslash\hspace{0pt}}b{#1}}
\newcolumntype{Q}[1]{>{\raggedleft \let\newline\\\arraybackslash\hspace{0pt}}b{#1}}

\setcellgapes{1.5pt}
\setlength{\arrayrulewidth}{0.05em}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Colours:

\colorlet{backLightYellow}{red!30!yellow!30!white!30}
\colorlet{framLightYellow}{black!30!yellow!30}
\colorlet{backDarkYellow}{black!30!red!30!yellow}
\colorlet{framDarkYellow}{red!30!yellow!40}

\colorlet{backLightBlue}{cyan!30!blue!10}
\colorlet{framLightBlue}{black!30!cyan!40!blue!20}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%-----------------------------------------------------------
%\usepackage{titling}
%
%\renewcommand\maketitlehooka{\null\mbox{}\vfill}
%\renewcommand\maketitlehookd{\vfill\null}
%-----------------------------------------------------------

\newcommand\Item[1][]{%
  \ifx\relax#1\relax  \item \else \item[#1] \fi
  \abovedisplayskip=0pt\abovedisplayshortskip=0pt~\vspace*{-\baselineskip}}

\newcommand\bs{\boldsymbol}
\renewcommand\bs[1]{\boldsymbol{#1}}

\setlength{\parindent}{0.7em}
\setlength{\parskip}{0.5em}
%===========================================================
%///////////////////////////////////////////////////////////

答案1

正如我已经说过的,不要尝试插入浮动环境。要添加图形标题,请将 tikzpicture 插入到\parbox相应宽度中并使用\captionof{figure}{...}。此外,不要在 tikzpicture 的代码中留下空行。最后一点:如果 TeX 没有计算出正确的短线数量,您可以使用补充短线的数量作为可选参数(与通常的方式相反,最后一个参数命令)。

\documentclass[a5paper,12pt,twoside,openany]{memoir}
\usepackage[a5paper]{geometry}
\usepackage{tikz}
\usepackage{caption}
\usepackage[latin]{babel}
\usepackage{lipsum}
\input{insbox}

\begin{document}

\InsertBoxL{0}{%
\parbox{4.6cm}
{ \begin{tikzpicture}[x=.25in,y=.25in]
        \draw [<-, thick] (0, 4.2) coordinate (Yin) node [above] {$y$}
                       -- (0, 0.0)
                       -- (0,-1.2) coordinate (Yout);
        \draw [->, thick] (-1.5,0) coordinate (Xin)
                       -- ( 0.0,0)
                       -- ( 4.5,0) coordinate (Xout) node [right] {$x$};
        \draw [thick] (2.8, 0.9) -- (1.8, 0.9) node [midway,below] {$\Delta x$};
        \draw [thick] (2.8, 0.9) -- (2.8, 1.4) node [midway,right] {$\Delta y$};
        \draw [domain=-1:4,variable=\x,red,thick] plot({\x},{(\x)/2});
    \end{tikzpicture}
\captionsetup{font=footnotesize}
  \captionof{figure}{Linear function}
    \label{fig:linear}
}}[6]
\noindent\lipsum[1-3]

\end{document} 

在此处输入图片描述

相关内容