TeX - LaTeX Asked on June 11, 2021
I am trying to make an enumerate list that should produce the list with tikz node and with automatic numbering e.g Problem 1:, Problem 1.1:, and Problem 2:.
I write the tikz code that only generates the single Problem by mentioning the number myself.
My code is as follows:
documentclass[a4paper, 12pt]{article}
usepackage{tikz}
usepackage[margin=1in]{geometry}
newcommand{tb}[1]{textbf{#1}}
tikzset{problem/.style={
fill=red!10,
text width=1textwidth-1cm,
rounded corners=0.2cm,
inner sep=0.5cm,
draw=red!60!black}
}
newcommand{problem}[1]
{
noindenttikz node[problem](instructions) {#1};
vspace{0.1cm}
}
begin{document}
problem{tb{Problem 1:} Explain the term Least Significant Bit (LSB).}
problem{tb{Problem 2:} Explain the term Most Significant Bit (MSB).}
problem{tb{Problem 2.1:} Why MSB is used?}
problem{tb{Problem 2.2:} Why LSB is used in x86 architecture?}
problem{tb{Problem 3:} Assemble the given program and update the values of the registers after single step execution.}
end{document}
How can I generate a similar list with enumerate environment with automatically numbering Problem 1:, Problem 1.1:, and Problem 2:, with the tikz node style (red background color and border)?
I would do this by tcolorbox and two counters:
documentclass{article}
usepackage[showframe=false,
margin=1in]{geometry}
usepackage{varwidth}
usepackage[most]{tcolorbox}
newcounter{mainno}
newcounter{subno}
newenvironment{myenumerate}
{setcounter{mainno}{0}setcounter{subno}{0}}{}
pgfmathsetlengthmacromysep{4mm}% 4mm = default of tcolorbox for left, right
tcbset{CommonStyle/.style={
boxrule=0.4pt, % default value TikZ
arc=3pt,
colframe=red!60!black, colback=red!10,
top=mysep, bottom=mysep,
left=mysep, right=mysep, %boxsep=0mm,
tcbox width=forced left,
beforeafter skip=1.125baselineskip,
},
}
newtcbox{subbox}[1][]{CommonStyle,
before upper={%
begin{varwidth}{dimexprlinewidth-mysep-myseprelax}%
stepcounter{subno}%
textbf{Problem themainno.thesubno:}~
},
after upper=end{varwidth}, #1}
newtcbox{mainbox}[1][]{CommonStyle,
before upper={%
begin{varwidth}{dimexprlinewidth-mysep-myseprelax}%
stepcounter{mainno}%
setcounter{subno}{0}%
textbf{Problem themainno:}~
},
after upper=end{varwidth}, #1}
begin{document}
begin{myenumerate}
% subbox{Sub item}
mainbox{Main item}
mainbox{Main item}
subbox{Sub item}
subbox{Sub item}
mainbox{Main item}
subbox{Sub item. This ia a very long text. This ia a very long text. This ia a very long text. This ia a very long text.}
end{myenumerate}
%begin{myenumerate}
% mainbox{Main item}
% subbox{Sub item}
% subbox{Sub item}
%end{myenumerate}
end{document}
Correct answer by cis on June 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP