Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a feeling that this is a profoundly stupid question but I cannot seem to solve it myself.

I am trying to write an own macro to create a boxed paragraph. The code works fine in-line but when I try to define the command it just creates a small box in the same place that I wrote the command. My codes are below. I am pretty much a complete newbie at this and any help would be greatly appreciated.

\fbox{\parbox{\linewidth}{Inline this works perfectly.}}

\newcommand{\note}{\fbox{\parbox{\linewidth}{}}}
share|improve this question
1  
Welcome to TeX.sx! –  Torbjørn T. Jan 5 '13 at 16:06

1 Answer 1

up vote 13 down vote accepted

In

\newcommand{\note}{\fbox{\parbox{\linewidth}{}}}

The content of the parbox is always specified by {} so empty.

\note{hello}

will make an empty box from \note before seeing hello.

You want hello to be an argument of \note so

\newcommand{\note}[1]{\fbox{\parbox{\linewidth}{#1}}}
share|improve this answer
    
And that's called a quick response! -- At the velocity of light! :-) –  Harish Kumar Jan 5 '13 at 16:10
    
Thanks a lot, that works beautifully. Much appreciated! –  Mara Jade Jan 5 '13 at 16:22
1  
@MaraJade \newcommand{\note}[1]{\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\rel‌​ax}{#1}}} is probably better. I’d throw in an additional \noindent too. –  Qrrbrbirlbel Jan 5 '13 at 18:17
1  
Yes do as @Qrrbrbirlbel says, I addressed the programming question about how to define a macro with arguments but \newcommand{\note}[1]{\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fbo‌​xrule\rel‌​ax}{#1}}} is a better definition in this case as otherwise the box will not fit on the line as the inner box is already full width and then outer box has padding and a rule on either side, and TeX may add paragraph indentation at the start. –  David Carlisle Jan 5 '13 at 18:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.