22

I would to build, for my students, a creative collection of exercises and problems. I am not very able, with my source in attachment, to create the same figure shown in attachment. Someone, please, could you help me?

enter image description here

    \documentclass[italian]{book}
    \usepackage{amssymb,latexsym, mathtools}
    \usepackage[utf8]{inputenc}
    \usepackage{babel}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \usepackage{stackengine,xcolor}
    \let\svitem\item
    \newcommand\difbox[1]{\stackengine{0pt}{\color{gray!30}\rule{5ex}{1.15ex}}{%
        \color{red}$\mkern1mu\makeballs{#1}$}{O}{c}{F}{F}{L}}
    \def\makeballs#1{\ifnum#1>0\relax{\bullet}%
      \expandafter\makeballs\the\numexpr#1-1\relax\fi}
    \newenvironment{benumerate}
    {\renewcommand\item[1][1]{\def\difficulty{##1}\svitem}%
      \def\labelenumi{\smash{\stackunder[1pt]{\color{teal}%
      \bfseries\sffamily\large\theenumi}{\difbox{\difficulty}}}}%
      \enumerate}{\endenumerate}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \usepackage{siunitx}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \usepackage{titlesec}
    \usepackage{multicol}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \usepackage[left=2.5cm, right=2.5cm, top=3cm, bottom=2cm]{geometry}
    % \usepackage[a4paper,left=2.5cm,right=2.5cm,top=1.5cm,bottom=1.5cm,
    % marginparsep=3mm,marginparwidth=18mm,
    %headheight=0mm,headsep=0cm,
    %footskip=1.5cm,includeheadfoot%,showframe
    %]{geometry}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



    \usepackage{fancyhdr} 
    \usepackage{tikz} 
    \usetikzlibrary{fadings}
    % Headers
    \definecolor{gray}{cmyk}{0,0,0,0.4}
    \definecolor{darkgrey}{cmyk}{0,0,0,0.6}

    \pagestyle{fancy}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
    \fancyhead{} % Remove head fields
    \fancyfoot{} % Remove foot fields
    \setlength{\headheight}{24pt}
     \fancyhead[RO]{\sffamily\bfseries\footnotesize\textcolor{gray}\leftmark\hspace{0.3cm}\sffamily\bfseries\normalsize\textcolor{darkgray}\thepage}
     \fancyhead[LE]{\sffamily\bfseries\textcolor{darkgray}\thepage\hspace{0.3cm}\sffamily\bfseries\footnotesize\textcolor{gray}\leftmark}
     \renewcommand{\headrulewidth}{0pt}
     \renewcommand{\footrulewidth}{0pt}
     \renewcommand{\headrule}{%
       \vskip-\baselineskip\vskip4pt
     \ifodd\count0\hfill\begin{tikzpicture}
    \fill[darkgray,path fading=west] (0,0) rectangle (4.98,0.02);
    \end{tikzpicture}\else\begin{tikzpicture}
    \fill[darkgray,path fading=east] (0,0) rectangle (4.98,0.02);
    \end{tikzpicture}\fi}
    \parindent0pt
    \parskip6pt
    \makeatletter
    \makeatother
    \newcounter{myExercise}[section]
    \setcounter{myExercise}{1}
    \newcommand\exercise{\textbf{Esercizi \thesection.\stepcounter{myExercise}\themyExercise.\,}}
    \newcommand\mySol[1]{\textcolor{cyan!20!blue}{[$#1$]}}
    \setlength{\columnsep}{12pt}
    \setlength\columnseprule{0pt}
    \begin{document}

    \section*{Velocità}


    \begin{multicols}{2}
    \begin{benumerate}

    \item[1] 

    Un'automobile transita al km 25 di un'autostrada alle ore 8:25 e transita al km 29 alle ore 8:27. Qual è la sua velocità media in km/h? \hfill\mySol{120\,\, \text{km/h}}


    \item[2] In autostrada ogni kilometro è contrassegnato da un numero. Guardando fuori dal finestrino, ti accorgi che passano 36 s   tra un cartello e l'altro. A quale velocità stai procedendo? \hfill\mySol{100\,\, \text{km/h}}

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

    %\item 

    \hfill\mySol{\ldots}
    \end{benumerate}

    \end{multicols}
    \end{document}
Sebastiano
  • 54,118
  • For reference, your original question: http://tex.stackexchange.com/questions/337356/create-a-custom-numbered-list-with-little-balls-and-gray-rectangle – Steven B. Segletes Dec 29 '16 at 20:48
  • Thank you so much for your help last time. I would simply make it more beautiful in relation to the header, adding designs and colors. I can tell that it is not the same question I asked. – Sebastiano Dec 29 '16 at 20:51
  • Yes, I understand this is a different topic. I just added the link for others to follow the train of thought from the outset. – Steven B. Segletes Dec 29 '16 at 20:54
  • In my source there will be unnecessary parts. I should still change everything; for example the package \geometry removing \setlength{\topmargin}{-.5in} etc. – Sebastiano Dec 29 '16 at 21:00
  • 3
    A few suggestions that have nothing to do with your question: to typeset quantities, use the package siunitx, it will give you much more consistency; since you are using the utf8 input encoding, if you have an Italian keyboard, you can write directly the accented letters àèéìòù, without the need of using the escape sequences \'e, etc.; for setting margins, you can use the geometry package. – Massimo Ortolano Dec 29 '16 at 21:17
  • I know the utf8 input encoding precisely to avoid the several sequences \'e, \'a etc. I used MAC few days ago. You can verify that I mentioned in the previous comment the package \geometry. Could you offer me using my source your idea? – Sebastiano Dec 29 '16 at 21:33
  • 3
    Note that questions about graphic design are off topic for this site (there is a separate stack exchange site for that) once you have chosen your design, asking how to implement it in TeX is of course on topic. (The topic boundaries are of course very vague and lots of overlap is allowed but I would say this question is pretty clearly off topic) – David Carlisle Dec 29 '16 at 21:40
  • Dear @David just wondering if you can do something with TikZ or other roads. Like putting a background, a color fringe side, etc. simply using LaTeX. – Sebastiano Dec 29 '16 at 21:45
  • 1
    Why \setlength{\topskip}{0in} ? (It will lead to uneven settings with the position of the first line of each page varying depending on the content of the line.) – David Carlisle Dec 29 '16 at 21:49
  • It would take many changes, since my source is also old and have not adapted to the changes. I apologize in advance if there are errors you can safely edit my source. Same can be said for other users. – Sebastiano Dec 29 '16 at 21:57
  • Don't load packages twice, e.g. xcolor, titlesec etc. – samcarter_is_at_topanswers.xyz Dec 29 '16 at 22:52
  • @samcarter Thanks. I'm editing by following your instructions. If there is something wrong you could edit my source, kindly? – Sebastiano Dec 29 '16 at 22:58
  • 6
    As I said before, this is not a good way to go about learning LaTeX. You need to break down This Complicated Thing into individual steps you can tackle one at a time. Then go about learning how to do each step. If you get stuck, ask a question about that particular step. By the way, in addition to the other comments, your font configuration could do with some attention. times is deprecated for a start. You are worrying far too much about all the twiddly bits, in my opinion, and not taking the time you need to learn the basics. – cfr Dec 30 '16 at 02:24
  • 1
    Don't change the layout dimensions manually if using geometry. If you say \setlength{\headheight}{24pt}, geometry doesn't know about this and things are bound to go wrong. For the new picture, look at tcolorbox and just work on that element. It would not be my priority if my page layout wasn't consistent yet, which is far more basic, but if you are determined to focus on bling, at least try to deal with one variety of bling at a time. tcolorbox will take some time and work on your part: it is a powerful package. – cfr Dec 31 '16 at 03:38
  • I kindly know the package is simple and powerful as you say. But it is not out of laziness. I'm very slow and I admit it. I would like to create the same image I have attached the section of which is also shown next to the number. At the moment I'm not capable. As you can see I answer on this site to simple questions. Appreciate my sincerity. I'll give you my best wishes for the New Year. – Sebastiano Dec 31 '16 at 12:44
  • If I may, I would like to ask how you add the colored red boxes with light red shadings, arrows, etc. to the output of the MWE? Thank you, – DDS Sep 25 '21 at 01:58
  • @mlchristians Hi, I have used an external program to modificate a .png image. Hence off-topic with the LaTeX. – Sebastiano Sep 25 '21 at 08:09

1 Answers1

13

I tried to reproduce the graphics and look, but more is to do and is left to the O.P, since there are some hard coded parts not really configurable.

The easiest positioning of the grade/skill level box can be achieved by using a tcolorbox and a TikZ node.

The \mylib code is 'stolen' from the tcolorbox documentation.

\documentclass[italian]{book}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{mathtools}

\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}

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

\usepackage{stackengine}
\usepackage{xcolor}

\newcommand\difbox[1]{\stackengine{0pt}{\color{gray!30}\rule{5ex}{1.15ex}}{%
    \color{red}$\mkern1mu\makeballs{#1}$}{O}{c}{F}{F}{L}}
\def\makeballs#1{\ifnum#1>0\relax{\bullet}%
  \expandafter\makeballs\the\numexpr#1-1\relax\fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[copy-decimal-marker,color=blue]{siunitx}
\usepackage{multicol}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[left=2.5cm, right=2.5cm, top=3cm, bottom=2cm]{geometry}
% \usepackage[a4paper,left=2.5cm,right=2.5cm,top=1.5cm,bottom=1.5cm,
% marginparsep=3mm,marginparwidth=18mm,
%headheight=0mm,headsep=0cm,
%footskip=1.5cm,includeheadfoot%,showframe
%]{geometry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{fancyhdr}  % Load fancyhdr after geometry!


\usepackage{tikz} 
\usetikzlibrary{fadings}


% Headers
\definecolor{gray}{cmyk}{0,0,0,0.4}
\definecolor{darkgrey}{cmyk}{0,0,0,0.6}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead{} % Remove head fields
\fancyfoot{} % Remove foot fields

\setlength{\headheight}{24pt}
\fancyhead[RO]{\sffamily\bfseries\footnotesize\textcolor{gray}\leftmark\hspace{0.3cm}\sffamily\bfseries\normalsize\textcolor{darkgray}\thepage}
\fancyhead[LE]{\sffamily\bfseries\textcolor{darkgray}\thepage\hspace{0.3cm}\sffamily\bfseries\footnotesize\textcolor{gray}\leftmark}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\renewcommand{\headrule}{%
  \vskip-\baselineskip\vskip4pt
  \ifodd\count0\hfill\begin{tikzpicture}
    \fill[darkgray,path fading=west] (0,0) rectangle (4.98,0.02);
  \end{tikzpicture}\else\begin{tikzpicture}
    \fill[darkgray,path fading=east] (0,0) rectangle (4.98,0.02);
  \end{tikzpicture}\fi}

\parindent0em
\parskip6pt

\setlength{\columnsep}{12pt}
\setlength{\columnseprule}{0pt}



\usepackage[most]{tcolorbox}

\newtcbox{\mylib}{enhanced,nobeforeafter,tcbox raise base,boxrule=0.4pt,top=0mm,bottom=0mm,
  right=0mm,left=4mm,arc=1pt,boxsep=2pt,before upper={\vphantom{dlg}},
  colframe=green!50!black,coltext=green!25!black,colback=green!10!white,
  overlay={\begin{tcbclipinterior}\fill[green!75!blue!50!white] (frame.south west)
    rectangle node[text=white,font=\sffamily\bfseries\tiny,rotate=90] {Tema} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}


\makeatletter

\newcommand{\exercisesidebox}[1]{%
  \def\difficulty{#1}%
  \stackunder[1pt]{\color{teal}\bfseries\sffamily\large\the\c@tcb@cnt@exercise}{\difbox{\difficulty}}%
}
\makeatother

\newcommand\mySol[1]{\textcolor{cyan!20!blue}{[$#1$]}}

\newtcolorbox[auto counter, number within=section]{exercise}[2][]{%
  right skip={20pt},
  enhanced jigsaw,
  sharp corners,
  frame hidden,
  colback=white,
  overlay={\node[xshift=0.3em,yshift=-1.5em] (A) at (frame.north west) {\exercisesidebox{#2}};} %Change the shift values to place the box more appropiately. 
  #1
}


\begin{document}


\section*{\mylib{Velocità}}


\begin{multicols}{2}

\begin{exercise}{1}
Un'automobile transita al \SI{25}{\kilo\meter} di un'autostrada alle ore 8:25 e transita al \SI{29}{\kilo\meter} alle ore 8:27. Qual è la sua velocità media in \si{\kilo\meter/\hour}? \hfill\mySol{\SI{120}{\kilo\meter/\hour}}
\end{exercise}
\begin{exercise}{2}
In autostrada ogni kilometro è contrassegnato da un numero. Guardando fuori dal finestrino, ti accorgi che passano \SI{36}{\second}   tra un cartello e l'altro. A quale velocità stai procedendo? \hfill\mySol{\SI{100}{\kilo\meter/\hour}}
\end{exercise}
\begin{exercise}{3}
Proof that there is a typesetting system better than \LaTeXe.
\end{exercise}
\end{multicols}
\end{document}

enter image description here

  • 1
    Please note that this is a starter only... I don't claim to fulfill all requirements here –  Jan 01 '17 at 19:19
  • Christian're a big. Casper :-) compared to you was an amateur: -? Allow me to joke with you. I certainly do not would never have done. When you have a bit more time doing others aesthetic retouch with \tcolorbox will very nice. At least I have a memory of your work. The size of the exercises numbers can be increased with a bold font? – Sebastiano Jan 01 '17 at 20:18
  • 1
    @Sebastiano: Actually, I've provided much of what you wanted. A bigger number is not really advantageous, in my point of view –  Jan 01 '17 at 20:51
  • You are a friend. Thank you very much. I have checked your answer. – Sebastiano Jan 01 '17 at 21:37
  • Christian no. I'm doing some tests to learn more about the site. Quiet, as you'll see I've given back to you the score. Look, I always vote your answers. I did not understand why Vox populi always arrive in 39/40, and I never take the badge. I vote the issues after 10 minutes. – Sebastiano Feb 08 '17 at 08:56
  • 1
    @Sebastiano: Unaccepting answers won't give you a badge ;-) You must not vote for answers but also for questions. You should vote for 10 questions and another 30 votes may distributed at will amongst questions and answers. See http://meta.stackexchange.com/a/188732/261926 –  Feb 08 '17 at 08:57