6

I would like to make a box like the figure below. Can you assist me with text code using tcolorbox? enter image description here

Thanks

  • Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – Stefan Pinnow Oct 16 at 18:37
  • Why does the inverted relation have an i and the non inverted one does not? – Schrödinger's cat Oct 17 at 0:56
2

I offer a solution based on the xcoffin package, not to compete with the other excellent solutions proposed, but to show the advantages of a great package.

Many questions posted in this forum relates with the positioning of various elements as graphics, tables, text, etc. on a page, in specific places and in relation with one another. In many cases against TeX wishes.

Over time I was able to replace geometry, rotate, titlepage, and similar packages with xcoffin, to design book covers, title-pages, posters, chapter styles, etc. thus avoiding conflicts and specially avoiding the dreadful time checking a full upgrade to discover that old projects not longer produce the same output or simply did not run at all.

To me the lesser number of packages, the better.

xcoffin provides only a handful of commands with intuitive meaning (at least for me) and does not require remembering dozens of keyvals or options. Excellent manual, by the way.

I also appreciate the fact that in the case of the one-time jobs mentioned earlier, the resulting code is very simple since there not need to contemplate multiple alternatives for the input and it is mostly auto-documented. Even if a book title changes over the course of a project, the corrections are straightforward.

Of course previously you need to produce the material, perhaps using amsmath, xcolor, tabularx, graphicx, ... and then fill the coffin with it.

Afterward you fit the coffins in the page using as origin the current text insertion point, or in relative positions among themselves, as could be the case of an image and a margin explanatory note. Then you typeset the result at the insertion point or in any other place of the page of your liking (a plus) since the resulting coffin it is not a float.

In this particular case only four coffins are required: the Output which will collect the others, a green rectangle, a side rule, and the inside text, as shown in the code. Both the rectangle and the rule adapts theirs height to the text content.

I also include a macro, to be moved to the preamble, to reduce the clutter of the document. For the fun of it, and supposing that several Definitions will be included in the document, I added a counter and applied the macro five times.

\documentclass{article}

\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{xcoffins,calc}

\begin{document}

%% Create and Set Coffins

\NewCoffin\Output   %Coffin to hold the others 
\NewCoffin\Definition % Definition definition ...
\NewCoffin\BackFrame % Background: green rectangle
\NewCoffin\SideRule  %lateral left border

\SetHorizontalCoffin\Output{} % It will provide the reference point to join the others

\SetVerticalCoffin\Definition{\linewidth}{%
\textbf{Definition.} $\gamma^5$ is defined to be the matrix given by:%
\[\gamma^5=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd} \]%
}

%% Make both \BackFrame & SideRule heights = height of Definition + 1*baselineskip
\SetHorizontalCoffin\BackFrame{\color{green!30!gray!15}\rule{\linewidth}{\CoffinTotalHeight\Definition + \baselineskip}}    

\SetHorizontalCoffin\SideRule{\color{green!50!black}\rule{3pt}{\CoffinTotalHeight\Definition +\baselineskip}} %vertical side rule 

%% Assembly Coffins
\JoinCoffins*\Output[l,t]\BackFrame[l,t] %attach left-top corner of BackFrame  to idem of Output
\JoinCoffins*\Output[l,t]\SideRule[l,t] %attach left-top corner of  SideRule to idem of Output
\JoinCoffins*\Output[l,t]\Definition[l,t](0pt,-\baselineskip) %attack left-top corner of Definition to idem of Output

%% now your document

We need some more meaningless test to for a multiline paragraph, because these form a basis for the space of all complex $4\times4$ matrices.

%% Typeset Definition
\noindent\TypesetCoffin\Output % at the text insertion point. It is not a float.
\vspace*{\CoffinTotalHeight\Definition}\bigskip %make some room for Output

We can invert this to obtain $ \epsilon_{abcd}i\gamma^{abcd} \lambda^{5}$, but we need som more meaningless test to for a multiline paragraph. 

%%%%%%%%%%%%%%%%%  macro def, to be moved  to the preamble, use as \SetDefinition{your-text}
\newcounter{defcounter}

\newcommand{\SetDefinition}[1]{%
    \SetHorizontalCoffin\Output{} % It will be the reference point join the others  
    \SetVerticalCoffin\Definition{\linewidth}{\textbf{Definition \stepcounter{defcounter}\Roman{defcounter}.} #1} %added counter

    %% Make both \BackFrame & SideRule heights = height of Definition + 1*baselineskip
    \SetHorizontalCoffin\BackFrame{\color{green!30!gray!15}\rule{\linewidth}{\CoffinTotalHeight\Definition + \baselineskip}}    
    \SetHorizontalCoffin\SideRule{\color{green!50!black}\rule{3pt}{\CoffinTotalHeight\Definition +\baselineskip}} %vertical side rule 

    %% Assembly Coffins
    \JoinCoffins*\Output[l,t]\BackFrame[l,t] %attach left-top corner of BackFrame  to idem of Output
    \JoinCoffins*\Output[l,t]\SideRule[l,t] %attach left-top corner of  SideRule to idem of Output
    \JoinCoffins*\Output[l,t]\Definition[l,t](0pt,-\baselineskip) %attack left-top corner of Definition to idem of Output
    %% Typeset ooutput
    \noindent\TypesetCoffin\Output % at the text insertion point. It is not a float.
    \vspace*{\CoffinTotalHeight\Definition}\bigskip %make some room for Output
}   
%%%%%%%%%%%%%%%%%%%%%   end macro

\SetDefinition{$\gamma^1$ is defined to be the matrix given by:\[\gamma^1=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd} \]}
\SetDefinition{$\gamma^2$ is defined to be the matrix given by:\[\gamma^2=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd} \]}
\SetDefinition{$\gamma^3$ is defined to be the matrix given by:\[\gamma^3=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd} \]}
\SetDefinition{$\gamma^4$ is defined to be the matrix given by:\[\gamma^4=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd} \]}
\SetDefinition{$\gamma^5$ is defined to be the matrix given above.\\} % a short Definition
\end{document}

Definition

8

The following might give you an idea on how to start:

enter image description here

\documentclass{article}
\usepackage[most]{tcolorbox}

\newtcolorbox{mybox}{
enhanced,
boxrule=0pt,frame hidden,
borderline west={4pt}{0pt}{green!75!black},
colback=green!10!white,
sharp corners
}

\begin{document}


\begin{mybox}
\textbf{Definition} My definition text here
\end{mybox}

\end{document}
6

A very light weight solution is to use a tabular. Not as sexy as \tcolorbox and other TikZ based solution, but it compiles fast. The simplest is to use a p-column as wide as the \linewidth.

  1. First I define a new column type N and calculate its width to \linewidth minus two tabcolsep. Then the table fits between the margins and will adapt if you change margins.

  2. Since we need some space above an below the "box", I have set the table inside a \center-environment to ensure that the table is fixed between the margins, and vertical space on par with other environments.

  3. Thereafter, I define the width and colour of the left vertical bar. I put the redefinition inside the centring environment, which limits the scope of the redefinitions to this taular. Without, all table rules will be green and 3 pt thick!

I have since yesterday slightly optimised the code. It is possible to define a new environment, and move most of the code to such definition. This may be useful if you have lot of boxes.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{array}

\newcolumntype{N}{@{}|>{\raggedright\arraybackslash\hspace{0pt}}p{\dimexpr(\linewidth-2\tabcolsep)}@{}}

\begin{document}

We need som more meaningless test to for a multiline paragraph, because these form a basis for the space of all compex $4\times4$ matrices.

\begin{center}
\setlength{\extrarowheight}{4pt}
\setlength{\arrayrulewidth}{3pt}
\arrayrulecolor{green!50!black}
\begin{tabular}{N}
\cellcolor{green!15}{
\textbf{Definition:} $\lambda^{5}$ is defined to be the matrix given by:
\medskip
\[\lambda^{5}=\dfrac{1}{14} \epsilon_{abcd}\gamma^{abcd} \]
}
\end{tabular}
\end{center}

We can invert this to obtain $ \epsilon_{abcd}i\gamma^{abcd} \lambda^{5}$, but we need som more meaningless test to for a multiline paragraph. 

\end{document}
6

I have used mdframed instead of tcolorbox (they are similar package but tcolorbox is mor complete than mdframed). You can see that you have the same result. Here there is my proposal where I have used for theorem, definition, examples, the specific package amsthm with the possibility to create a book: see the specific class of the document \documentclass[12pt]{book}. For to increase the tickness vertical green line you can to change the value linewidth=2.5pt. This example sets the text in italic:

\documentclass[12pt]{book}
\usepackage{amsthm}
\usepackage{amsmath,amssymb}
\usepackage[svgnames]{xcolor}
\RequirePackage[framemethod=default]{mdframed}
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
linecolor=Green,
backgroundcolor=Green!10,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=2pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=2.5pt,
innerbottommargin=5pt]{dBox}    
\newenvironment{definition}{\begin{dBox}\begin{definitionT}}{\end{definitionT}\end{dBox}}
\newtheorem{definitionT}{Definition}[section]

\begin{document}
\begin{definition}
$\gamma^5$ is defined to be a matrix given by:
\[\gamma^5=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd}\]
\end{definition}
\end{document}

enter image description here

Another code sets the text in roman adding \theoremstyle{definition}. See this MWE:

enter image description here

\documentclass[12pt]{book}
\usepackage{amsthm}
\usepackage{amsmath,amssymb}
\usepackage[svgnames]{xcolor}
\RequirePackage[framemethod=default]{mdframed}
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
linecolor=Green,
backgroundcolor=Green!10,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=2pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=2.5pt,
innerbottommargin=5pt]{dBox}
\theoremstyle{definition}
\newenvironment{definition}{\begin{dBox}\begin{definitionT}}{\end{definitionT}\end{dBox}}
\newtheorem{definitionT}{Definition}[section]

\begin{document}
\begin{definition}
$\gamma^5$ is defined to be a matrix given by:
\[\gamma^5=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd}\]
\end{definition}
\end{document}
5

In case that you do not use tcolorbox or tikz for anything else, is a bit overkill use it for a simple box. What I see is AMS theorem-like environment with the definition style in a green box with a vertical rule beside, so I made defined the \definition command that make just that. Note that macros cannot have paragraph breaks, so, if you need will that, define a new environment instead of a macro.

The advantage of use the amsthm package just to write "definition" in bold is that you can just remove the asterisk of line 7 to have numbered definitions that you can reference by the usual \label-- \ref method.

mwe

\documentclass{article}
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{lipsum}

\theoremstyle{definition}
\newtheorem*{defi}{Definition}
\def\definition#1{\par\medskip\noindent{\color{green!50!black}\vrule width 3pt}%
\colorbox{green!30!gray!15}{\parbox[c]{\dimexpr\linewidth-3pt-2\fboxsep-2\fboxrule}
{\begin{defi}#1\end{defi}}}\par\medskip}

\begin{document}

\lipsum[1][1-4]

\definition{$\gamma^5$ is defined to be the matrix given by: 
\[\gamma^5=\frac{1}{24}\epsilon_{abcd}\gamma^{abcd} \]}

\lipsum[2][1-5]

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.