3

I would like to add a key word beside a paragraph for the sake of clarity as follows

enter image description here

\documentclass[12pt]{article}
\usepackage{blindtext}

\begin{document}
\blindtext

\end{document}

How can I fulfill this goal?

  • Should it always be on the same side (to the left)? Do you have a preference in terms of the interface? – Werner Jul 29 '15 at 22:22
  • 2
    \documentclass[12pt]{article} \usepackage{blindtext} \usepackage{marginnote} \usepackage{xcolor} \reversemarginpar \begin{document} \marginnote{\textcolor{red}{\small Key note}}\blindtext \end{document} – Gonzalo Medina Jul 29 '15 at 22:23
  • Yes. This key word sums up the paragraph. No preference just bold font. – CroCo Jul 29 '15 at 22:24
  • @GonzaloMedina, thank you. I would accept it if you post it as an answer. How to control the distance? It is very close to the paragraph. – CroCo Jul 29 '15 at 22:28
  • @CroCo Please see the answer below. – Gonzalo Medina Jul 29 '15 at 22:56
3

One option is yo use \marginnote from the marginnote package; using the geometry package you can change marginparsep (the separation between the marginal note and the regular text) and/or marginparwidth the width reserved for the note:

\documentclass[12pt]{article} 
\usepackage[marginparsep=25pt]{geometry} 
\usepackage{blindtext} 
\usepackage{marginnote} 
\usepackage{xcolor} 

\newcommand\KeyWord[1]{%
  \marginnote{\parbox[t]{\marginparwidth}{\raggedright\small \textcolor{red}{#1}}}}
\reversemarginpar 

\begin{document} 

\KeyWord{Key note}\blindtext 

\end{document}

The result:

enter image description here

3

Just add it. ;-)

\documentclass{article}

\newcommand{\KW}[1]{%
  \par % ensure vertical mode
  \leavevmode % start a paragraph
  {\setbox0=\lastbox}% remove the indentation box
  \makebox[0pt][r]{\textbf{#1}\hspace{2em}}% print the keyword
  \hspace*{\parindent}% add the parindent
  \ignorespaces
}

\begin{document}

This paragraph has no keyword, it has some boring text just to
make it wrap across a couple of lines.

\KW{key word}
This paragraph has a keyword, it has some boring text just to
make it wrap across a couple of lines.

\end{document}

enter image description here

1

Here is a key-value interface which allows you to adjust the separation, the font and color:

enter image description here

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{xcolor,xkeyval}

\makeatletter
\define@cmdkey{KW}{sep}{}
\define@cmdkey{KW}{color}{}
\define@cmdkey{KW}{font}{}
\newcommand{\KeyWord}[2][]{%
  \par\noindent
  \setkeys{KW}{#1}%
  \makebox[0pt][r]{\textcolor{\cmdKV@KW@color}{\cmdKV@KW@font #2}\hspace*{\cmdKV@KW@sep}}%
  \hspace*{\parindent}\ignorespaces
}
\makeatother
\newcommand{\KeyWordsetup}[1]{\setkeys{KW}{#1}}%
\AtBeginDocument{\KeyWordsetup{font=\bfseries,color=red,sep=\marginparsep}}% defaults

\begin{document}

\KeyWord{Key note}\lipsum[1]

\KeyWord[sep=20pt]{Key Note}\lipsum[2]

\KeyWord[font=\itshape,color=blue!50]{KEY NOTE}\lipsum[3]

\KeyWordsetup{font=\slshape,color=red,sep=\marginparsep}%
\KeyWord{Key note}\lipsum[4]
\end{document}

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.