fmarotta / kaobook

A LaTeX class for books, reports or theses based on https://github.com/kenohori/thesis and https://github.com/Tufte-LaTeX/tufte-latex.

Home Page:https://github.com/fmarotta/kaobook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tcolorbox idea + example

JamesMRamm opened this issue · comments

Summary

Hey there! This isn't so much a request, as an example. Last night I came up with a tcolorbox solution to replace the kaobox that I thought was worth sharing. I've barely used GitHub, so hopefully this is the right way to do this. 😅

Big disclaimer: I've only been using latex for about a week, so I might've overlooked some glaring issue. I've been putting together a business plan for the past few months, and I got fed up with MS Word's inconsistencies, so I converted it to latex.

Details

With the example below, you should be able to create a new box style in one line of code:

\tcbcreate{env_name}{box_title}{base_colour}{fontawesome_icon}

Here's an example of what it'll produce:

example

If you're interested, later on I can show you the other modifications I'm making to the class, but it's definitely not in a 'typical' latex style anymore. To figure out how it all works, and make it easier for me to modify, I pulled the code apart and reorganised it into packages which are progressively loaded by the class in order by:

  1. style-level (brand colours, fonts, i18n, etc.)
  2. page-level
  3. environment-level
  4. book-level

Example Code

Minimal Example
% Example of tcolorbox boxes

\documentclass[10pt]{article}

\RequirePackage[usenames,dvipsnames,table]{xcolor}
\RequirePackage[fixed]{fontawesome5}
\RequirePackage{tcolorbox}

\tcbuselibrary{most}

% Brand Colours

\definecolor{primary}{HTML}{124889} % primary blue
\definecolor{secp}{HTML}{8E0883} % secondary purple
\definecolor{secy}{HTML}{D1CE0C} % secondary yellow
\definecolor{tertg}{HTML}{317658} % tertiary green
\definecolor{terto}{HTML}{EB8A16} % tertiary orange

% General box settings:

\tcbset{%
    enhanced,
    before skip balanced=2mm,
    after skip balanced=3mm,
    boxrule=0.4pt,
    sharp corners,
    left=10mm, right=2mm, % control text position
    top=1mm, bottom=1mm,
    drop small lifted shadow=black,
    fonttitle=\bfseries
}

% Command to create new boxes:

\newcommand{\tcbcreate}[4]{
    \newtcolorbox{#1}[1][]{
        colback=#3!10!white,
        colframe=#3,
        title=#2,
        underlay={%
            \path[fill=#3!80!white,draw=none] (interior.south west) rectangle
            node[#3!5!white]{\Large\bfseries#4} ([xshift=8mm]interior.north west);
        }
    }
}

% Boxes to be used in document:

\tcbcreate{boxinfo}{Further Information}{primary}{\faLightbulb[regular]}
\tcbcreate{boxexample}{Practical Example}{tertg}{\faComments[regular]}
\tcbcreate{boxquestion}{Outstanding Question}{terto}{\faExclamationCircle}

\begin{document}
    \begin{boxinfo}
        hello world
    \end{boxinfo}

    \begin{boxexample}
        hello world
    \end{boxexample}

    \begin{boxquestion}
        hello world
    \end{boxquestion}
\end{document}