2010-10-17 162 views
4

我想定義一個LaTeX命令,在每個字母后插入一個空格。LaTeX:每個字母后的空格

所以,如果我添加

\addSpaces{someText} 

結果應該是

s o m e T e x t 

我怎麼能做到這一點?

背景:我想每個字母加下劃線,但該行應的字母之間分割:

s o m e T e x t 
_ _ _ _ _ _ _ _ 

NOT: 
s o m e T e x t 
_______________ 
+0

所以......沒的其中之一鍛鍊你嗎?仍然有麻煩? – 2010-10-20 14:19:41

回答

3

可以使用soul package的下劃線。對於單個單詞,您可以使用我在下面寫的\addspaces宏。 (宏將吞字與字之間的空間。一個簡單的解決方法是使用\四,增加單詞之間的空格。)

\documentclass{article} 

\usepackage{soul}% provides underlining 

\makeatletter% since we're using a macro containing @ 
\newcommand{\addspaces}[1]{% 
    \@tfor\letter:=#1\do{% 
    \ul{\letter}\space 
    }% 
} 
\makeatother% resets @ to its original meaning 

\begin{document} 

% Works fine for single words 
\addspaces{Spaces} 

% Note that spaces in between words aren't preserved -- use \quad to add extra space. 
\addspaces{Spaced\quad and\quad underlined.} 

\end{document} 
1

對於文本的程序操作,我覺得它更容易使用perltex定義perl函數來執行代碼然後編譯文檔。請參閱CTAN

這是一個快速和骯髒。

\documentclass{article} 
\usepackage{perltex} 

\perlnewcommand{\ulspace}[1]{ 
$input = shift; 
$input =~ s/(\w)/\\underline\{\1\} /g; 
return $input; 
} 

\begin{document} 

\ulspace{Hello World} 

\end{document} 

編譯:

perltex --latex=pdflatex myfile.tex 
相關問題