19

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}
  • 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
  • 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
  • 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
  • 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 2: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 3:38
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 – user31729 Jan 1 '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 1 '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 – user31729 Jan 1 '17 at 20:51
  • You are a friend. Thank you very much. I have checked your answer. – Sebastiano Jan 1 '17 at 21:37
  • 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 meta.stackexchange.com/a/188732/261926 – user31729 Feb 8 '17 at 8:57

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.