4

When I insert a shadowbox using Lyx (Insert>Box>Drop Shadow) the width is specified as 100% of column width (1\columnwidth). This is the source code it generates:

\shadowbox{\begin{minipage}[t]{1\columnwidth}%
My shadowbox content goes here.%
\end{minipage}}

The column width seems like a poor default choice since any indentation moves the shadowbox into the right-hand margin.* I'd like to make the line width (1\linewidth) the default width so boxes only extend up to the right-hand margin.

I tried redefining the \shadowbox command in my preamble but the parameter I'm trying to change is actually part of the \minipage inside the shadowbox and I haven't figured out how to access it.

I've also tried redefining the width of the frame based on this excerpt from the documentation:

\shadowbox

The width of the frame is \fboxrule (the same as with \fbox). The width of the shadow is \shadowsize (default: 4pt).

by adding this line to my preamble:

\setlength{\fboxrule}{\linewidth}

It did not produce the results I expected (below). Is there a straightforward way to specify shadowboxes use line, not column, width by default?

Results of setting \fboxrule to \linewidth


Footnotes

* The shadowbox command was redefined in my preamble to ignore paragraph indenting

\let\oldshadowbox\shadowbox
\renewcommand{\shadowbox}[1]{%
  \noindent \oldshadowbox{#1}}

But sometimes indentation is preferable such as when placing shadowboxes under list items

4
  • Does \linewidth is OK for you? You just only to make it as a default when using the menu to insert the box?
    – Sigur
    Commented Apr 17, 2014 at 0:12
  • Setting the \fboxrule does only change the thickness of the frame but not the width of the box itself. (Well, in same sense it did ;-))
    – user31729
    Commented Apr 17, 2014 at 0:14
  • @Sigur Yes, I'd like to use \linewidth as the default when I insert a box via 'Insert>Box>Drop shadow' Commented Apr 17, 2014 at 17:05
  • 1
    @ChristianHupfer I can see now I didn't read the documentation literally enough. Good observation Commented Apr 17, 2014 at 17:08

3 Answers 3

1

I'd suggest you to use \linegoal from the linegoal package (requires two compilations). Of course, you also need to take into account the padding of the box and the width of the shadow, so the width would be

-\fboxsep-\shadowsize+\linegoal

A complete example:

\documentclass{article}
\usepackage{fancybox}
\usepackage{linegoal}
\usepackage{showframe}

\begin{document}

\noindent\shadowbox{\begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}%
My shadowbox content goes here.%
\end{minipage}}

some test text\shadowbox{\begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}%
My shadowbox content goes here.%
\end{minipage}}

some longer test text for the example\shadowbox{\begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}%
My shadowbox content goes here.%
\end{minipage}}

\end{document}

enter image description here

And you can make this the default behaviour using a command:

\documentclass{article}
\usepackage{fancybox}
\usepackage{linegoal}

\let\Oldshadowbox\shadowbox

\renewcommand\shadowbox[1]{%
  \Oldshadowbox{%
  \begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}
  #1
  \end{minipage}}%
}  

\begin{document}

\noindent\shadowbox{My shadowbox content goes here.}

some test text\shadowbox{My shadowbox content goes here.}

some longer test text for the example\shadowbox{My shadowbox content goes here My shadowbox content goes here My shadowbox content goes here My shadowbox content goes here My shadowbox content goes here.}

\end{document}

enter image description here

2
  • Ah I see why my attempts to redefine \shadowbox failed; thank you for the helpful answer @GonzaloMedina Commented Apr 17, 2014 at 20:54
  • Ultimately, what I want is to modify Lyx's behavior but I have marked your answer as accepted for its completeness. I do believe it carries the same caveat as my answer below though: users can not 'override' this method to set different widths for individual boxes. Commented Apr 17, 2014 at 21:16
2

In LyX, follow the menu Edit > Box Settings... Here you can change the box width to measure \linewidth:

enter image description here

This should update your LaTeX code accordingly:

enter image description here

1
  • Thanks @Werner this is my current procedure. I was hoping to make \linewidth the default Commented Apr 17, 2014 at 17:10
0

@GonzaloMedina provides a valid and useful answer. I have found a simpler solution based on his second example code block. It will not work in all situations but handles my case:

% in the preamble:
\let\oldshadowbox\shadowbox
\renewcommand{\shadowbox}[1]{%
  \noindent \oldshadowbox{%
    \begin{minipage}[t]{1\linewidth}
    #1
    \end{minipage}}%
}

Do realize this does not affect how Lyx inserts \shadowboxs, only how they are rendered in output. Consequently, users of this approach can no longer set widths on individual cases. (This is an issue with Lyx itself, not LaTeX.) Since the minipage with the shadowbox will be re-wrapped in a minipage of width 1\linewidth the width of text within the box is affected but box width is not.

You must log in to answer this question.

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