2

I want to be able to have some text aligned in the left margin such as a theorem label, and then have the example in the mdframed box. Here is an example of my failed attempt.

enter image description here

As you can see the text "this is a test" is slighly pushed right. Here is the code for this example

\documentclass[18pt]{article}

\usepackage{mdframed}
\newcommand{\sdef}{ %
\hspace*{-2in}\makebox[2in]{\hfill \textbf{Definition 1.1.1.1} \hspace*{.35in}}}

\newenvironment{definition} 
{\begin{mdframed}[linewidth=2pt,roundcorner=8pt,align=center]
\vspace*{5px}%
\sdef}
{\vspace*{5px}
\end{mdframed}}

\begin{document}
\begin{definition}
    This is a test \\
    Here is more text.
\end{definition}
\end{document}

How do I properly align that first sentence? Thank you in advance.

EDIT: Another solution that I came across was to use the \ignorespaces macro so replacing the defintion of sdef with this works

\newcommand{\sdef}{ %
\hspace*{-2in}\makebox[2in]{\hfill \textbf{Definition 1.1.1.1} \hspace*{.35in}}\ignorespaces}
  • 1
    While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Dec 24 '18 at 17:54
  • 1
    @marmot I'm not terribly good at sketches but all I want is for that first sentence "This is a test" to be left aligned to the same point where the "Here is more text" sentence is. – Nick Dec 24 '18 at 18:15
1

Here is a work-around, inserting a negative interword space at the beginning of the environment:

\documentclass[18pt]{article}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\usepackage{mdframed}
\newcommand{\sdef}{ %
\hspace*{-2in}\makebox[2in]{\hfill \textbf{Definition 1.1.1.1}\hspace*{.35in}}}

\newenvironment{definition}
{\begin{mdframed}[linewidth=2pt,roundcorner=8pt,align=center]%
\vspace*{5px}%
\sdef\hspace*{-\fontdimen2\font}}
{\vspace*{5px}
\end{mdframed}}

\begin{document}

\begin{definition}
This is a test \\
    Here is more text.
\end{definition}
\end{document} 

enter image description here

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.