如何在段落旁边添加关键词?

如何在段落旁边添加关键词?

为了清楚起见,我想在段落旁边添加一个关键词,如下所示

在此处输入图片描述

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

\begin{document}
\blindtext

\end{document}

我怎样才能实现这个目标?

答案1

一个选项是\marginnote使用marginnote包;使用几何包,您可以更改marginparsep(边注和常规文本之间的分隔)和/或marginparwidth为注释保留的宽度:

\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}

结果:

在此处输入图片描述

答案2

只需添加它。;-)

\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}

在此处输入图片描述

答案3

这是一个键值接口,允许您调整分配sepfontcolor

在此处输入图片描述

\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}

相关内容