2

I come from this link and the response that is given is very good.

I have this MWE:

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\vspace{5mm}
\fbox{\begin{minipage}{30em}
    \underline{\textbf{NOTACI\'ON}}: Dada \(f:D\subseteq \mathbb R\rightarrow \mathbb R\) con \(y=f(x)\) para denotar la funci\'on derivada se puede encontrar en la bibliograf\'ia disponible de la materia las siguientes notaciones: \[\begin{array}{cccc}f'(x), & D_xf, & \dfrac{df}{dx}, & \dfrac{dy}{dx}\end{array}.\]  Todas ellas son equivalentes y que utilizaremos indistintamente en lo sucesivo.
\end{minipage}}
\vspace{5mm}

\end{document}

where I modify the fbox value (which is 30em) manually. But that is not the correct width of box (according to the margins of the document). So I change 30emfor \textwidth value, and when I compile it says that there is an Bad Box (I clarify that approximately from 31em onwards the Bad Box message appears). How can I avoid that message?

Using a measure versus not using it

Should I manually enter the value or is there some (easy) way to not have to worry about every box in my document?

Thanks!

  • 1
    There is a little bit white space (fboxsep) on all sides of the box to the text. This space is added to the linewidth, hence the whole box needs more space and creates a warning. – Johannes_B Jan 22 '18 at 7:16
  • 2
    What you really should do: Create semantic markup, instead of doing the layout each and every time. – Johannes_B Jan 22 '18 at 7:17
  • 3
    To resolve you immediate issue instead of \textwidth use \begin{minipage}{\textwidth-2\fboxsep} and include \usepackage{calc}. Also, you need a \noindent before the \fbox{}. But, yes defintly do as @Johannes_B recommends and define a custom environment instead of tweaking every use of this. I'd recomment looking into tcolorbox (there are numerous examples on this site). Also, adding the showframe package will clearly show you what is happening with you add the \noindent and the -2\fboxsep. – Peter Grill Jan 22 '18 at 7:37
  • @Johannes_B Thanks for your explanation! I am a beginner with LaTeX, so I have to learn a lot about programming (even if I'm studying a career in Computer Science haha). – manooooh Jan 22 '18 at 20:38
  • @PeterGrill I'm going to take your recommendation about that alternative that you propose. – manooooh Jan 22 '18 at 20:38
2

Here is a "changed" fbox called \myfbox and expecting as arguments an optional for width and a mandatory (its content)

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\newlength{\mywidth}%

\makeatletter
\newcommand\myfbox[2][\linewidth]{%
\xdef\mysep{\dimexpr 1\dimexpr\f@size pt\relax\relax}%
\setlength{\fboxsep}{\mysep}%
\setlength{\mywidth}{\dimexpr#1-2\fboxsep-2\fboxrule\relax}%
\noindent\fbox{\begin{minipage}[inner sep=0]{\mywidth}#2\end{minipage}}%
}%
\makeatother

\begin{document}

\Large

\myfbox[\linewidth]{
\underline{\textbf{NOTACI\'ON}}: Dada \(f:D\subseteq \mathbb R\rightarrow \mathbb R\) con \(y=f(x)\) para denotar la funci\'on derivada se puede encontrar en la bibliograf\'ia disponible de la materia las siguientes notaciones: \[\begin{array}{cccc}f'(x), & D_xf, & \dfrac{df}{dx}, & \dfrac{dy}{dx}\end{array}.\]  Todas ellas son equivalentes y que utilizaremos indistintamente en lo sucesivo.}


Dada \(f:D\subseteq \mathbb R\rightarrow \mathbb R\) con \(y\) para denotar la funci\'on derivada se puede encontrar en la bibliograf\'ia disponible de la materia las siguientes notaciones:

\normalsize

\myfbox[\textwidth]{\underline{\textbf{NOTACI\'ON}}: Dada \(f:D\subseteq \mathbb R\rightarrow \mathbb R\) con \(y=f(x)\) para denotar la funci\'on derivada se puede encontrar en la bibliograf\'ia disponible de la materia las siguientes notaciones: \[\begin{array}{cccc}f'(x), & D_xf, & \dfrac{df}{dx}, & \dfrac{dy}{dx}\end{array}.\]  Todas ellas son equivalentes y que utilizaremos indistintamente en lo sucesivo.}

\scriptsize

\begin{center}
\myfbox[0.7\textwidth]{\underline{\textbf{NOTACI\'ON}}: Dada \(f:D\subseteq \mathbb R\rightarrow \mathbb R\) con \(y=f(x)\) para denotar la funci\'on derivada se puede encontrar en la bibliograf\'ia disponible de la materia las siguientes notaciones: \[\begin{array}{cccc}f'(x), & D_xf, & \dfrac{df}{dx}, & \dfrac{dy}{dx}\end{array}.\]  Todas ellas son equivalentes y que utilizaremos indistintamente en lo sucesivo.}
\end{center}
\end{document}

Output:

enter image description here

PS: Source: https://tex.stackexchange.com/a/102739/120578 from @GonzaloMedina

PS2: May be is not good idea to include the \noindent command in my definition of the box (You can remove it from there and use it whenever needed)

  • Many thanks! It is fine with \noident command :). The only thing I have to add was the vertical spacing up and down the custom box you created so that the text is not so close to it. I should learn all the commands that you use in your code. What draws my attention is the meaning of the \relax command and all that ... I'm passionate about LaTex! – manooooh Jan 22 '18 at 20:46

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.