1

I am trying to use \hspace to align text inside mdframed box. However, \hspace seems to not working inside mdframed box. Text in the mdframed is somehow is aligned to center. Why is \hspace not working here ?

\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{shadows}
\newmdenv[shadow=true,shadowcolor=black,font=\sffamily, align=right, leftmargin=10pt]{shadowbox}


\begin{shadowbox}
\hspace{2cm} 90   \hspace{1cm}  [NOP]   \newline
\hspace{2cm} 8bff \hspace{1cm}  [MOV EDI, EDI] (FUNCTION ENTRY) \newline
\hspace{2cm} 90   \hspace{1cm}  [NOP]   \newline
\hspace{2cm} 90   \hspace{1cm}  [NOP] \newline
\hspace{2cm} 90   \hspace{1cm}  [NOP] \newline
\hspace{2cm} 90   \hspace{1cm}  [NOP] \newline
\hspace{2cm} 8bff \hspace{1cm}  [MOV EDI, EDI] (FUNCTION ENTRY) \newline
\hspace{2cm} 55   \hspace{1cm}  [PUSH EBP] \newline
\hspace{2cm} 8bec \hspace{1cm} [MOV EBP, ESP] \newline
\end{shadowbox}

Following is the result I am getting now :

enter image description here

2
  • As far as I know the first \hspace should be \hspace*, because there is no text before the command. Further it seems that your problem has to do with the align option of your mdframed environment. I personally would use a tabular inside the mdframed environment to align the op codes. Commented May 17, 2015 at 14:51
  • Unusual approach. Why you not use table for this formatting. To me with it is more natural an of course more easy way.
    – Zarko
    Commented May 17, 2015 at 14:52

2 Answers 2

2

After \newline spacing such as \hspace is ignored; you can force it to work with \hpsace* instead. Try this little example to see what happens:

\noindent
Text\newline
\hspace{2cm}text\newline
\hspace*{2cm}text.

Sample output

However, what you probably want is a tabbing environment, otherwise the columns are not going to line up. Compare the first example below with tabbing with the second, which is what your modified input would give:

Sample output

\documentclass{article}

\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{shadows}
\newmdenv[shadow=true,shadowcolor=black,font=\sffamily, align=right,
  leftmargin=10pt]{shadowbox}

\begin{document}

\begin{shadowbox}
  \begin{tabbing}
    \hspace{2cm} \= 90   \hspace{1cm} \= [NOP] \\
    \> 8bff \>  [MOV EDI, EDI] (FUNCTION ENTRY) \\
    \> 90   \>  [NOP]   \\
    \> 90   \>  [NOP] \\
    \> 90   \>  [NOP] \\
    \> 90   \>  [NOP] \\
    \> 8bff \>  [MOV EDI, EDI] (FUNCTION ENTRY) \\
    \> 55   \>  [PUSH EBP] \\
    \> 8bec \> [MOV EBP, ESP] \\
  \end{tabbing}
\end{shadowbox}

\begin{shadowbox}
\hspace*{2cm} 90   \hspace{1cm}  [NOP]   \newline
\hspace*{2cm} 8bff \hspace{1cm}  [MOV EDI, EDI] (FUNCTION ENTRY) \newline
\hspace*{2cm} 90   \hspace{1cm}  [NOP]   \newline
\hspace*{2cm} 90   \hspace{1cm}  [NOP] \newline
\hspace*{2cm} 90   \hspace{1cm}  [NOP] \newline
\hspace*{2cm} 90   \hspace{1cm}  [NOP] \newline
\hspace*{2cm} 8bff \hspace{1cm}  [MOV EDI, EDI] (FUNCTION ENTRY) \newline
\hspace*{2cm} 55   \hspace{1cm}  [PUSH EBP] \newline
\hspace*{2cm} 8bec \hspace{1cm} [MOV EBP, ESP] \newline
\end{shadowbox}

\end{document}

The first line of tabbing provides a template, with \= setting the tabstops. On subsequent lines \> moves to the next tab.

1

or by using tabularx:

\documentclass{article}

\usepackage{tabularx}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{shadows}
\newmdenv[shadow=true,shadowcolor=black,font=\sffamily, 
          align=right, leftmargin=10pt]{shadowbox}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{shadowbox}% <-- just for showing only the shadowbox
    \setlength\PreviewBorder{1em}


    \begin{document}
\begin{shadowbox}
    \begin{tabularx}{\hsize}{>{\setlength\hsize{0.5\hsize}\qquad}XXX}
90   &  [NOP]           &                       \\
8bff &  [MOV EDI, EDI]  &   (FUNCTION ENTRY)    \\
90   &  [NOP]           &                       \\
90   &  [NOP]           &                       \\
90   &  [NOP]           &                       \\
90   &  [NOP]           &                       \\
8bff &  [MOV EDI, EDI]  &   (FUNCTION ENTRY)    \\
55   &  [PUSH EBP]      &                       \\
8bec &  [MOV EBP, ESP]  &
    \end{tabularx}
\end{shadowbox}
    \end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .