TeX - LaTeX Asked on April 15, 2021
I would to write text and draw symbols next to some boxes, without affecting at all the positions of the boxes, as shown in the image below.
I tried the following code but it does affect the positions of the boxes.
How can I fix it?
documentclass{article}
usepackage{tcolorbox}
usepackage{showframe}
usepackage{harmony}
newtcolorbox{myFrame}
{colback = red, colframe = white, top = 0mm, bottom = 0mm, boxrule = 0pt, left = 2mm, right = 2mm}
begin{document}
vbox to0cm
{hspace{-2cm}hbox to2cm{AchtAcht} par
hspace{-2cm}hbox to2cm{small{}easy}}
begin{myFrame}
Exercice 2.3par
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
vbox to0cm
{hspace{-2cm}hbox to2cm{Acht} par
hspace{-2cm}hbox to2cm{small{}medium}}
begin{myFrame}
Exercice 2.4par
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
{medskiplargecentering bf With the symbols and texts in the marginpar}
%% Without the symbols+text in the margin
%begin{myFrame}
%Exercice 2.3par
%This is the text of the exercise.par
%By the way, I use tcolorbox to make my boxes.
%end{myFrame}
%
%begin{myFrame}
%Exercice 2.4par
%This is the text of the exercise.par
%By the way, I use tcolorbox to make my boxes.
%end{myFrame}
%
%{medskiplargecentering bf Without the symbols and texts in the marginpar}
end{document}
Is this the way you want it to look like? I was not sure about the alignment of the symbols inside the boxes, but you could easily make them raggedleft
if needed.
documentclass{article}
usepackage{tcolorbox}
usepackage{showframe}
usepackage{harmony}
newtcolorbox{myFrame}
{colback = red, colframe = white, top = 0mm, bottom = 0mm, boxrule = 0pt, left = 2mm, right = 2mm}
newcommand{easy}{%
llap{parbox[t][0pt]{1.7cm}{%
AchtAchtpar
small{}easy
}}%
}
newcommand{medium}{%
llap{parbox[t][0pt]{1.7cm}{%
Achtpar
small{}medium
}}%
}
begin{document}
begin{myFrame}
easy
Exercice 2.3par
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
begin{myFrame}
medium
Exercice 2.4par
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
{medskiplargecentering bf With the symbols and texts in the marginpar}
end{document}
Correct answer by schoekling on April 15, 2021
Admittedly not perfect since the rounded corners are missing and the boxes are not automatically numbered, but probably the following could serve as a starting point:
documentclass{article}
usepackage[most]{tcolorbox}
usepackage{showframe}
usepackage{harmony}
usepackage{calc}
usepackage{changepage}
newlength{myleftcolwidth}
setlength{myleftcolwidth}{widthof{small medium}}
newtcolorbox{mybox}{sidebyside,
sidebyside align=top seam,
boxrule=0pt,
boxsep=3pt,
sharp corners,
lefthand width=myleftcolwidth,
lower separated=true,
sidebyside gap=3mm,
bicolor,
colback=white,
colbacklower=red,
left=3pt}
newenvironment{myexercise}[2]%
{%
begin{adjustwidth*}{-myleftcolwidth-3mm-2.5pt}{}%
begin{mybox}%
hfillbegin{tabular}[t]{@{}r@{}}#1 small #2 end{tabular}%
tcblower%
}%
{%
end{mybox}%
end{adjustwidth*}%
}
usepackage{lipsum}
begin{document}
begin{myexercise}{AchtAcht}{easy}
lipsum[5]
end{myexercise}
begin{myexercise}{Acht}{medium}
lipsum[1][1-4]
end{myexercise}
begin{myexercise}{}{}
lipsum[1][1-4]
end{myexercise}
end{document}
Answered by leandriis on April 15, 2021
This is a solution with boxes numbered automatically and commends on left margin added with a overlay
. Comments contents is a mandatory parameter which can be left empty.
documentclass{article}
usepackage[most]{tcolorbox}
usepackage{showframe}
usepackage{harmony}
newtcolorbox[auto counter, number within=section]{myFrame}[2][]
{enhanced, attach title to upper=, title=Exercice~thetcbcounter, coltitle=black, colback = purple!60, colframe = white, top = 0mm, bottom = 0mm, boxrule = 0pt, left = 2mm, right = 2mm,
overlay={node[anchor=north east, align=right] at (frame.north west) {#2};},#1}
begin{document}
section{one section}
section{another section}
begin{myFrame}{AchtAcht{small easy}}
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
begin{myFrame}{AchtAcht{small medium}}
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
{medskiplargecentering bf With the symbols and texts in the marginpar}
% Without the symbols+text in the margin
begin{myFrame}{}
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
begin{myFrame}{}
This is the text of the exercise.par
By the way, I use tcolorbox to make my boxes.
end{myFrame}
{medskiplargecentering bf Without the symbols and texts in the marginpar}
end{document}
Answered by Ignasi on April 15, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP