如何在 \begin{document} 之前在 tcolorbox 环境中插入图形

如何在 \begin{document} 之前在 tcolorbox 环境中插入图形

为了在我的表单中插入徽标图片,我想使用 tcolorbox,但我不知道如何创建一个新环境以将其包含在 \begin{document} 之前的节点内。

这是我的代码,可以用 xelatex 正确编译

   \documentclass[12pt,a4paper]{report} \usepackage[top=13cm,bottom=1.5cm,right=1.5cm,left=2.5cm]{geometry} \usepackage{eso-pic} 
\usepackage{tikz,varwidth,multicol}
\usepackage[most]{tcolorbox} 
\pagestyle{empty} 
\definecolor{fff}{RGB}{249, 212, 6} 
\definecolor{vvv}{RGB}{47, 138, 58}
\definecolor{ccc}{RGB}{255,140,0} 
\definecolor{ggg}{RGB}{250,250,250} 
\tikzset{a/.style={anchor=west,line width=1.5pt,font=\bfseries\Large,rounded corners=2mm,draw=black,text=black,inner xsep=5mm,minimum height=1.5cm,rotate=-90}} 
\usetikzlibrary{calc}

\newcommand{\image}[3][1]{\includegraphics[width=#1\textwidth,height=#2\textheight,keepaspectratio]{#3}}
\renewcommand{\labelenumi}{ 
\begin{tikzpicture}[baseline=(1.base)] \node[circle,fill=fff,text=black,font=\bfseries,minimum size=5mm,inner sep=0mm](1){\arabic{enumi}}; 
\end{tikzpicture} } 
\AddToShipoutPicture{ 
\begin{tikzpicture}[remember picture,overlay]
\node [fill=fff,minimum width=\paperheight,minimum height=2cm,anchor=south east,rotate=-90](0)at ([xshift=0cm]current page.south west){}; 
\node[a](2)at($(0.west)!.9!(0.east)$){\image[0.1]{0.9}{./images/logo}
}; 
 
\end{tikzpicture} }
%---- define the border of exercice ------%
\newtcolorbox[auto counter]{exo}{breakable,top=1cm,title={Exercice \thetcbcounter},enhanced,before skip=5mm,after skip=5mm,boxsep=3mm,coltitle=black,attach boxed title to top left={xshift=5mm,yshift=-\tcboxedtitleheight},boxrule=.5pt,boxed title style={interior empty,frame code={ \fill([xshift=1mm]frame.north east)arc(180:0:1mm)([xshift=-1mm]frame.north west)arc(0:180:1mm); \path[right color=fff,left color=fff,middle color=fff!60] ([shift={(-.2,.1)}]frame.north west)--([shift={(.2,.1)}]frame.north east)[rounded corners=1mm]--([xshift=.1cm]frame.north east)--(frame.south east)--(frame.south west)--([xshift=-.1cm]frame.north west)[sharp corners]--cycle; } }}\usepackage{polyglossia}
\setmainlanguage{french} 
\newfontfamily\frenchfont{Times New Roman}
\begin{document}
\vspace{15cm}
\begin{exo} 
Recopier et compléter les égalités suivantes:
\begin{enumerate} 
\item $7\times15-\cdots )=70$ 
\item $5\times13-5\times\cdots =50$
\item $17\times(3.4+\cdots)=170$
\item $23\times2.3+23\times\cdots=230$
\end{enumerate}
\begin{center}
\begin{tcolorbox}[width=0.3\textwidth,height=0.13\textheight,
    enhanced,clip upper,%<------------
    colframe=red,colback=gray,boxrule=1pt,arc=10pt,
    boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt]
     \includegraphics[width=\textwidth, height=0.13\textheight]{./images/logo}
\end{tcolorbox} \end{center}
\end{exo} 

\end{document}

当我编译此代码时,我得到以下文档 修复边距中的填充尺寸图像 有人能帮忙去掉图片左边空白处吗?非常感谢。

答案1

我想你想要这样的东西。我定义了一个myboxedlogo带有三个参数的命令:可选的 tcolorbox 参数、includegraphics 参数和图形名称。此命令用于将徽标包含在主页和左边距中。

顺便说一句,tcolorbox我没有使用命令,而是使用了tcbincludegraphics命令。

\documentclass[12pt,a4paper]{report} \usepackage[top=13cm,bottom=1.5cm,right=1.5cm,left=2.5cm]{geometry} 
\usepackage{eso-pic} 
\usepackage{tikz,varwidth,multicol}
\usepackage[most]{tcolorbox} 
\pagestyle{empty} 
\definecolor{fff}{RGB}{249, 212, 6} 
\definecolor{vvv}{RGB}{47, 138, 58}
\definecolor{ccc}{RGB}{255,140,0} 
\definecolor{ggg}{RGB}{250,250,250} 

\tikzset{a/.style={inner sep=0pt}} 
\usetikzlibrary{calc}

\newcommand{\image}[3][1]{\includegraphics[width=#1\textwidth,height=#2\textheight,keepaspectratio]{#3}}

\renewcommand{\labelenumi}{ 
\begin{tikzpicture}[baseline=(1.base)] \node[circle,fill=fff,text=black,font=\bfseries,minimum size=5mm,inner sep=0mm](1){\arabic{enumi}}; 
\end{tikzpicture} } 

\newcommand{\myboxedlogo}[3][]{%
\tcbincludegraphics[hbox, size=tight, colframe=red, boxrule=1pt, arc=10pt, auto outer arc, clip upper, #1, graphics options={#2}]{#3}
}

\AddToShipoutPicture{ 
\begin{tikzpicture}[remember picture,overlay]
\node [fill=fff,minimum width=\paperheight,minimum height=2cm,anchor=south east,rotate=-90](0)at ([xshift=0cm]current page.south west){}; 
\node[inner sep=0pt](2)at($(0.west)!.9!(0.east)$){\myboxedlogo{width=.1\textwidth, height=0.9\textheight, keepaspectratio, angle=-90}{example-image-a}};
\end{tikzpicture} }

%---- define the border of exercice ------%
\newtcolorbox[auto counter]{exo}{breakable,top=1cm,title={Exercice \thetcbcounter},enhanced,before skip=5mm,after skip=5mm,boxsep=3mm,coltitle=black,attach boxed title to top left={xshift=5mm,yshift=-\tcboxedtitleheight},boxrule=.5pt,boxed title style={interior empty,frame code={ \fill([xshift=1mm]frame.north east)arc(180:0:1mm)([xshift=-1mm]frame.north west)arc(0:180:1mm); \path[right color=fff,left color=fff,middle color=fff!60] ([shift={(-.2,.1)}]frame.north west)--([shift={(.2,.1)}]frame.north east)[rounded corners=1mm]--([xshift=.1cm]frame.north east)--(frame.south east)--(frame.south west)--([xshift=-.1cm]frame.north west)[sharp corners]--cycle; } }}\usepackage{polyglossia}
\setmainlanguage{french} 
\newfontfamily\frenchfont{Times New Roman}
\begin{document}
\vspace{15cm}
\begin{exo} 
Recopier et compléter les égalités suivantes:
\begin{enumerate} 
\item $7\times15-\cdots )=70$ 
\item $5\times13-5\times\cdots =50$
\item $17\times(3.4+\cdots)=170$
\item $23\times2.3+23\times\cdots=230$
\end{enumerate}
\begin{center}
%\begin{tcolorbox}[width=0.3\textwidth,height=0.13\textheight,
%    enhanced,clip upper,%<------------
%    colframe=red,colback=gray,boxrule=1pt,arc=10pt,
%    boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt]
%     \includegraphics[width=\textwidth, height=0.13\textheight]{example-image-a}
%\end{tcolorbox} 
\myboxedlogo[colframe=blue]{width=.3\textwidth, height=0.13\textheight}{example-image-a}
\end{center}
\end{exo} 

\end{document}

在此处输入图片描述

相关内容