Theses, Books, Title pagesCleaner code for Remark-like environment ?

Classicthesis, Bachelor and Master thesis, PhD, Doctoral degree
Post Reply
pierre92
Posts: 13
Joined: Fri Jun 19, 2015 4:19 pm

Cleaner code for Remark-like environment ?

Post by pierre92 »

Hi all,
I have modified the "Remark" environment of the legrand-orange-book template for my conclusions. The changes are the addition of a color title followed by a line on the remaining width of the environment as well as a colored line underneath the last line.
The following code works like a charm:

Code: Select all

\documentclass{book}                
\usepackage{lipsum}
\usepackage{tikz} 				% Required for drawing custom shapes
\definecolor{cbleu}{RGB}{0,131,171} %custom color 1
\definecolor{cbleu2}{RGB}{26,176,230} %custom color 2

\newenvironment{conclusion}{\par\vspace{10pt} % Vertical white space above the envrnmt
\begin{list}{}{
\leftmargin=25pt % Indentation on the left
\rightmargin=15pt}\item\ignorespaces % Indentation on the right
\makebox[-2.5pt]{\begin{tikzpicture}[overlay,baseline=(char.base)]
\node[draw=cbleu2!60,line width=1pt,circle,fill=cbleu2!25,font=\sffamily\bfseries,inner sep=2pt,outer sep=0pt] at (-15pt,0pt)(char){\textcolor{cbleu}{C}};\end{tikzpicture}} % Blue C in a darker blue circle
\normalfont\normalsize\sffamily\bfseries{\textcolor{cbleu}{Conclusion}}	%defines the title of the paragraph with a paragraph style
\normalfont
\noindent\textcolor{cbleu}{\hrulefill}%keep the next line empty so that the text starts on a new line. 

\advance\baselineskip -1pt}{\newline\textcolor{cbleu}{\hrulefill}\end{list}\vskip10pt} % Tighter line spacing and white space after conclusion

\begin{document}
\lipsum[1]
\begin{conclusion}
\lipsum[1-2]
blablabla not too long
\end{conclusion}
\lipsum[1]
\end{document}
What I am not completely satisfied with is the empty line to ensure that the text of the conclusion actually starts as on a new line.
In addition, I may end up defining several of these environments. If it were a command I would do a renewcommand with 4 parameters (title, letter to be encircled, color1, color2) but with an environment is there something equivalent ?
Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cleaner code for Remark-like environment ?

Post by Johannes_B »

You can do something like the following, but i bet packages like tcolorbox or mdframed will be more suited and flexible for the job.

Code: Select all

\documentclass{book}                
\usepackage{lipsum}
\usepackage{tikz}                               % Required for drawing custom shapes
\definecolor{cbleu}{RGB}{0,131,171} %custom color 1
\definecolor{cbleu2}{RGB}{26,176,230} %custom color 2


\newcommand{\boxtitle}{ATTENTION}
\colorlet{boxfill}{white!10!black}
\colorlet{boxfont}{black!10!white}
\newcommand{\circleletter}{x}

\newenvironment{basicbox}{\par
%\vspace{-10pt}% Vertical white space above the envrnmt
\begin{list}{}{%
\leftmargin=25pt % Indentation on the left
\rightmargin=15pt}\item\ignorespaces% Indentation on the right
\makebox[-2.5pt]{\begin{tikzpicture}[overlay,baseline=(char.base)]
\node[draw=boxfill!60,line width=1pt,circle,fill=boxfill!25,font=\sffamily\bfseries,%
inner sep=2pt,outer sep=0pt] at (-15pt,0pt)(char){\textcolor{boxfont}{\circleletter}};\end{tikzpicture}
}%
\normalfont\normalsize\sffamily\bfseries{\textcolor{boxfont}{\boxtitle}}%defines the title of the paragraph with a paragraph style
\normalfont
\noindent\textcolor{boxfont}{\hrulefill}\par
\advance\baselineskip -1pt}{\par\noindent\textcolor{boxfont}{\hrulefill}\end{list}\vspace{10pt}} % Tighter line spacing and white space after conclusion



\newenvironment{alarm}{%
	\renewcommand{\boxtitle}{ALARM}
	\renewcommand{\circleletter}{A}
	\colorlet{boxfill}{orange}
	\colorlet{boxfont}{red}
	\begin{basicbox}
	}{\end{basicbox}}
\newenvironment{conclusion}{%
	\renewcommand{\boxtitle}{Conclusion}
	\renewcommand{\circleletter}{C}
	\colorlet{boxfill}{cbleu}
	\colorlet{boxfont}{blue}
	\begin{basicbox}
	}{\end{basicbox}}

\begin{document}
\lipsum[1]
\begin{conclusion}
\lipsum[1-2]
blablabla not too long
\end{conclusion}
\begin{basicbox}
\lipsum[1-2]
blablabla not too long
\end{basicbox}
\begin{alarm}
\lipsum[1-2]
blablabla not too long
\end{alarm}
\begin{conclusion}
\lipsum[1-2]
blablabla not too long
\end{conclusion}
\lipsum[1]
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
pierre92
Posts: 13
Joined: Fri Jun 19, 2015 4:19 pm

Re: Cleaner code for Remark-like environment ?

Post by pierre92 »

Thank you very much. This is indeed much cleaner. I shall have a look at the packages you mention and let you know if I can make it more flexible. Cheers
Post Reply