LaTeX 样式框

LaTeX 样式框

我需要创建这个:

在此处输入图片描述

我有一个包含此代码的 LaTeX 文件,但我无法使用样式来归档文本:

\newlength\sidebar
\newlength\envrule
\newlength\envborder

\addtolength{\voffset}{-0.7in}
\addtolength{\textheight}{1.5in}

\setlength\sidebar{1.5mm}
\setlength\envrule{0.4pt}
\setlength\envborder{2.5mm}

\definecolor{noteborder}{rgb}{.5,.5,.5}
\definecolor{notebg}{rgb}{.95,.95,.95}
\definecolor{exampleborder}{rgb}{.22,.22,.555}
\definecolor{examplebg}{rgb}{.9,.9,1}
\definecolor{statementborder}{rgb}{.9,0,0}
\definecolor{statementbg}{rgb}{1,.9,.9}
\definecolor{theoremborder}{rgb}{0,0,0}
\definecolor{theorembg}{rgb}{.77,.88,.66}
\definecolor{ruzova}{rgb}{1,0.8,0.8}
\definecolor{zluta}{rgb}{1,1,0.5}
\definecolor{hrasek}{rgb}{0.79,1,0.45}

\newsavebox\envbox

\definecolor{red}{rgb}{0.9, 0, 0}

\newcounter{prik}[section] 
\renewcommand{\theprik}{\thesection.\arabic{prik}} 
\newcommand{\priklad}[1]{\refstepcounter{prik}\paragraph*{Příklad \theprik} #1} 

\newcounter{veta}[section]

\newenvironment{veta}[1][]{%
\par
\refstepcounter{veta}%

%\SpecialEnv{#1}{OliveGreen}{theorembg}{}{}%
\SpecialEnv{#1}{green!50!black}{theorembg}{}{}%
}{%
\endSpecialEnv
}

\newenvironment{statement}[1][]{% Default statement has no title
\par
\SpecialEnv{#1}{statementborder}{statementbg}{statementborder}{}%
}{%
\endSpecialEnv
}


\def\Empty{}

% #1 title (if any)
% #2 sidebar (and title bg) color
% #3 background color
% #4 border color (or null for no border)
% #5 Counter, if any.
\newenvironment{SpecialEnv}[5]{%
\par
\def\EnvSideC{#2}% To use later (in end)
\def\EnvBackgroundC{#3}%
\def\EnvFrameC{#4}%
\flushleft


\setlength\leftskip{-\sidebar}%
\addtolength\leftskip{-\envborder}%
\noindent \nobreak
% Check if title is null:
\ifx\delimiter {VÃTA \thesection.\theveta\ #1}\delimiter\else
% If a title is specified, then typeset it in reverse color
\colorbox{\EnvSideC}{%
\hspace{-\leftskip}% usually positive
\hspace{-\fboxsep}%
\footnotesize\sffamily\bfseries\textcolor{white}{VÃTA \thesection.\theveta\ #1}%
\hspace{\envborder}}%
\par\nobreak
\setlength\parskip{-0.2pt}% Tiny overlap to counter pixel round-off errors
\nointerlineskip
\fi


% Make side-bar
\textcolor{\EnvSideC}{\vrule width\sidebar}%
% collect body in \envbox:
\begin{lrbox}\envbox
\begin{minipage}{\hsize}%


% insert counter, if any:
\ifx\delimiter#5\delimiter\else
\theveta.\enspace
\fi
\ignorespaces
}{\par
\end{minipage}\end{lrbox}%
% body is collected. Add background color
\setlength\fboxsep\envborder
\ifx\EnvFrameC\Empty % no frame
\colorbox{\EnvBackgroundC}{\usebox\envbox}%
\else % frame
\setlength\fboxrule\envrule
\addtolength\fboxsep{-\envrule}%
\fcolorbox{\EnvFrameC}{\EnvBackgroundC}{\usebox\envbox}%
\fi
\nobreak \hspace{-2\envborder}\null
\endflushleft
}

%************************************************************************

\newcounter{definice}[section]

\newenvironment{definice}[1][DEFINICE \thesection.\thedefinice]{%                               %
\par
\refstepcounter{definice}%

%\SpecialEnva{#1}{RedOrange}{statementbg}{}{}%
\SpecialEnva{#1}{red!70}{red!15}{}{}%
}{%
\endSpecialEnva
}

\newenvironment{statementa}[1][]{% Default statement has no title
\par
\SpecialEnva{#1}{statementborder}{statementbg}{statementborder}{}%
}{%
\endSpecialEnva
}


\def\Empty{}

% #1 title (if any)
% #2 sidebar (and title bg) color
% #3 background color
% #4 border color (or null for no border)
% #5 Counter, if any.
\newenvironment{SpecialEnva}[5]{%
\par
\def\EnvSideC{#2}% To use later (in end)
\def\EnvBackgroundC{#3}%
\def\EnvFrameC{#4}%
\flushleft


\setlength\leftskip{-\sidebar}%
\addtolength\leftskip{-\envborder}%
\noindent \nobreak
% Check if title is null:
\ifx\delimiter#1\delimiter\else
% If a title is specified, then typeset it in reverse color
\colorbox{\EnvSideC}{%
\hspace{-\leftskip}% usually positive
\hspace{-\fboxsep}%
\footnotesize\sffamily\bfseries\textcolor{white}{#1}%
\hspace{\envborder}}%
\par\nobreak
\setlength\parskip{-0.2pt}% Tiny overlap to counter pixel round-off errors
\nointerlineskip
\fi


% Make side-bar
\textcolor{\EnvSideC}{\vrule width\sidebar}%
% collect body in \envbox:
\begin{lrbox}\envbox
\begin{minipage}{\hsize}%


% insert counter, if any:
\ifx\delimiter#5\delimiter\else
\thedefinice.\enspace
\fi
\ignorespaces
}{\par
\end{minipage}\end{lrbox}%
% body is collected. Add background color
\setlength\fboxsep\envborder
\ifx\EnvFrameC\Empty % no frame
\colorbox{\EnvBackgroundC}{\usebox\envbox}%
\else % frame
\setlength\fboxrule\envrule
\addtolength\fboxsep{-\envrule}%
\fcolorbox{\EnvFrameC}{\EnvBackgroundC}{\usebox\envbox}%
\fi
\nobreak \hspace{-2\envborder}\null
\endflushleft
}


%************************************************************************

\newcounter{poznamka}[section]

\newenvironment{poznamka}[1][POZN¡MKA \thesection.\thepoznamka]{%
\par
\refstepcounter{poznamka}%

\SpecialEnvb{#1}{noteborder}{notebg}{}{}%
}{%
\endSpecialEnvb
}

\newenvironment{statementb}[1][]{% Default statement has no title
\par
\SpecialEnvb{#1}{statementborder}{statementbg}{statementborder}{}%
}{%
\endSpecialEnvb
}


\def\Empty{}

% #1 title (if any)
% #2 sidebar (and title bg) color
% #3 background color
% #4 border color (or null for no border)
% #5 Counter, if any.
\newenvironment{SpecialEnvb}[5]{%
\par
\def\EnvSideC{#2}% To use later (in end)
\def\EnvBackgroundC{#3}%
\def\EnvFrameC{#4}%
\flushleft


\setlength\leftskip{-\sidebar}%
\addtolength\leftskip{-\envborder}%
\noindent \nobreak
% Check if title is null:
\ifx\delimiter#1\delimiter\else
% If a title is specified, then typeset it in reverse color
\colorbox{\EnvSideC}{%
\hspace{-\leftskip}% usually positive
\hspace{-\fboxsep}%
\footnotesize\sffamily\bfseries\textcolor{white}{#1}%
\hspace{\envborder}}%
\par\nobreak
\setlength\parskip{-0.2pt}% Tiny overlap to counter pixel round-off errors
\nointerlineskip
\fi


% Make side-bar
\textcolor{\EnvSideC}{\vrule width\sidebar}%
% collect body in \envbox:
\begin{lrbox}\envbox
\begin{minipage}{\hsize}%


% insert counter, if any:
\ifx\delimiter#5\delimiter\else
\thepoznamka.\enspace
\fi
\ignorespaces
}{\par
\end{minipage}\end{lrbox}%
% body is collected. Add background color
\setlength\fboxsep\envborder
\ifx\EnvFrameC\Empty % no frame
\colorbox{\EnvBackgroundC}{\usebox\envbox}%
\else % frame
\setlength\fboxrule\envrule
\addtolength\fboxsep{-\envrule}%
\fcolorbox{\EnvFrameC}{\EnvBackgroundC}{\usebox\envbox}%
\fi
\nobreak \hspace{-2\envborder}\null
\endflushleft
}








\newcounter{obr}[section]
\newcommand{\newobr}{\arabic\thesection.\arabic{obr}}
\def\obrazek#1#2#3{%
 \begin{minipage}{10cm}
 \refstepcounter{obr}
    \begin{center}\scalebox{#1}{%
        \includegraphics*{#2}
        }\\
        \begin{center}Obr·zek \thesection.\arabic{obr} {\it #3}\end{center}
    \end{center}
    \end{minipage}
}

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

\newcounter{dusledek}[section]

\newenvironment{dusledek}[1][DŸSLEDEK \thesection.\thedusledek]{%
\par
\refstepcounter{dusledek}%

\SpecialEnvc{#1}{exampleborder}{examplebg}{}{}%
}{%
\endSpecialEnvc
}

\newenvironment{statementc}[1][]{% Default statement has no title
\par
\SpecialEnvc{#1}{statementborder}{statementbg}{statementborder}{}%
}{%
\endSpecialEnvc
}


\def\Empty{}

% #1 title (if any)
% #2 sidebar (and title bg) color
% #3 background color
% #4 border color (or null for no border)
% #5 Counter, if any.
\newenvironment{SpecialEnvc}[5]{%
\par
\def\EnvSideC{#2}% To use later (in end)
\def\EnvBackgroundC{#3}%
\def\EnvFrameC{#4}%
\flushleft


\setlength\leftskip{-\sidebar}%
\addtolength\leftskip{-\envborder}%
\noindent \nobreak
% Check if title is null:
\ifx\delimiter#1\delimiter\else
% If a title is specified, then typeset it in reverse color
\colorbox{\EnvSideC}{%
\hspace{-\leftskip}% usually positive
\hspace{-\fboxsep}%
\footnotesize\sffamily\bfseries\textcolor{white}{#1}%
\hspace{\envborder}}%
\par\nobreak
\setlength\parskip{-0.2pt}% Tiny overlap to counter pixel round-off errors
\nointerlineskip
\fi


% Make side-bar
\textcolor{\EnvSideC}{\vrule width\sidebar}%
% collect body in \envbox:
\begin{lrbox}\envbox
\begin{minipage}{\hsize}%


% insert counter, if any:
\ifx\delimiter#5\delimiter\else
\thedusledek.\enspace
\fi
\ignorespaces
}{\par
\end{minipage}\end{lrbox}%
% body is collected. Add background color
\setlength\fboxsep\envborder
\ifx\EnvFrameC\Empty % no frame
\colorbox{\EnvBackgroundC}{\usebox\envbox}%
\else % frame
\setlength\fboxrule\envrule
\addtolength\fboxsep{-\envrule}%
\fcolorbox{\EnvFrameC}{\EnvBackgroundC}{\usebox\envbox}%
\fi
\nobreak \hspace{-2\envborder}\null
\endflushleft
}

你能告诉我它是怎么做到的吗?:)

答案1

您可以使用tcolorbox包裹:

\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}

\definecolor{mybox}{RGB}{246,51,46}

\newtcolorbox[auto counter,number within=section]{mydefi}{
  enhanced,
  breakable,
  arc=0pt,
  outer arc=0pt,
  rightrule=0pt,
  toprule=0pt,
  bottomrule=0pt,
  leftrule=3pt,
  colframe=mybox,
  colback=mybox!30,
  attach boxed title to top left,
  boxed title style={size=small,colback=red,arc=0pt,outer arc=0pt,colupper=white},
  title=Definice~\thetcbcounter,
}

\begin{document}

\begin{mydefi}
\lipsum[1]
\end{mydefi}

\end{document}

在此处输入图片描述

相关内容