Close

Making a text with surrounding box using MDFRAMED package LATEX step by step

How to use MDFRAMED package in LaTeX.

By     : Koredianto Usman

Date : August 22, 2017

Sometimes in your document, you want to have something like this:  

This kind of box helps our report or book look nice.   In this short tutorial, we will show you a step by step box design using mdframed package in LaTeX.   The official explaination of mdframed package is written by Marco Daniel and Elke Schubert.   The mdframed package is simply called by command:   \usepackage{mdframed}   This command is issued at  preamble.   So the typically LaTeX command is:   \documentclass{article} \usepackage{mdframed} \begin{document}   \end{document}

  1. Making a simple box

First we start with a very basic code. To make a simple new environment, called kotak, we define it with a command in LaTeX preambel:

\newmdenv[]{kotak}

This line instruct LaTeX to create a new environment called kotak (an Indonesian language means ‘box’) without any argument []. The typically LaTeX command is

\documentclass{article}    

\usepackage{mdframed}    

\newmdenv[]{kotak}

\begin{document}

\end{document}

 

After we define kotak environment, now we can use it in our document. For example :

\documentclass{article}    

\usepackage{mdframed}    

\newmdenv[]{kotak}

\begin{document}

\section{Introduction}

This is an example of creating a box using mdframed package.

\begin{kotak}

     If a right triangle has the length of 3 cm and 4 cm, what is the length of hypotenuse? Please use the Pythagoras identity      

    \begin{equation} c^2 = a^2+b^2. \end{equation}

\end{kotak}

\end{document}

Here, in this example, the text If a right triangle has the length of 3 cm and 4 cm…, is put between environment kotak (\begin{kotak}  … \end{kotak}).

After we compile, we get the following result.

Quite good for this simple code.

In the next example, we adjust the topmargin, bottom margin, leftmargin, and right margin of our box.

2. ADJUSTING MARGIN.

In above example, text above the box is too close to the box.  We want to make it a bit loose.

As reference, the following figure is the terminology of the margin in mdframed package.

So, in order to put distance between the text above the box and the box itself, we arrange the skipabove parameter.

\documentclass{article}    

\usepackage{mdframed}    

\newmdenv[skipabove=6mm]{kotak}   %here we arrange the skipabove distance to be 6mm

\begin{document}

\section{Introduction}

This is an example of creating a box using mdframed package.

\begin{kotak}

     If a right triangle has the length of 3 cm and 4 cm, what is the length of hypotenuse? Please use the Pythagoras identity      

    \begin{equation} c^2 = a^2+b^2. \end{equation}

\end{kotak}

\end{document}      

The result of this code is

 

Ok. Now our box has 6mm distance from above text. Of course we can arrange other margin to. For example the leftmargin, belowskip, and rightmargin. Just put a comma between these options.

\newmdenv[skipabove=6mm, skipbelow=4mm, leftmargin=4mm, rightmargin=4mm]{kotak}

3. ADDING THE TITLE OF THE BOX.

We can add the title of the box (which is called frametitle in this package).

\documentclass{article}    

\usepackage{mdframed}    

\newmdenv[skipabove=6mm]{kotak}   %here we arrange the skipabove distance to be 6mm

\begin{document}

\section{Introduction}

This is an example of creating a box using mdframed package.

\begin{kotak}[frametitle=Phytagoras theorem]

     If a right triangle has the length of 3 cm and 4 cm, what is the length of hypotenuse? Please use the Pythagoras identity      

    \begin{equation} c^2 = a^2+b^2. \end{equation}

\end{kotak}

\end{document}      

Even better.

Next we adjust the inner margin.

4. ADJUSTING INNER MARGIN

 

 

 

Leave a Reply

© 2022 Supporting website for my lecture. | WordPress Theme: Annina Free by CrestaProject.
%d bloggers like this: