答案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
这是一个键值接口,允许您调整分配sep
、font
和color
:
\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}