TexStudio has a nice option of aligning given tabular environment by choosing LaTeX > Manipulate Tables > Align Columns
from the menu or clicking this icon on the toolbar:
So something rough like this
\documentclass[10pt,a4paper]{article}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
fo1 & fo2 & fo3 \\
\hline
foob1 & foob2 & foob3 \\
\hline
foobar1 & foobar2 & foobar3 \\
\hline
\end{tabular}
\end{document}
becomes more readable:
\documentclass[10pt,a4paper]{article}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
fo1 & fo2 & fo3 \\ \hline
foob1 & foob2 & foob3 \\ \hline
foobar1 & foobar2 & foobar3 \\ \hline
\end{tabular}
\end{document}
But I feel really stupid as I cannot find the way to beautify the code for all the tables in a document at once. By choosing this option even if the entire document is selected I can only automatically align one table at a time, so I need to manually click through all the tables.
Is there something I am missing?
Similar question also goes for the alignment about =
sign, e.g. in BIB-files, where
@article{Foo1970,
title = {Lorem Ipsum},
pages = {451},
number = {42},
date = {1970-01-01},
journaltitle = {TUG},
author = {Foo, Bar},
}
should look like
@article{Foo1970,
title = {Lorem Ipsum},
pages = {451},
number = {42},
date = {1970-01-01},
journaltitle = {TUG},
author = {Foo, Bar},
}
or in preamble when certain parameters are passed to the package:
\usepackage[
math-style = ISO,
bold-style = ISO,
partial = upright,
nabla = upright
]{unicode-math}
visually better:
\usepackage[
math-style = ISO,
bold-style = ISO,
partial = upright,
nabla = upright
]{unicode-math}
Is there a unified way to align the code for entire document using TexStudio (or other means as a last resort) around &
and =
?
Best Answer
Since you already have solutions for the Table alignment with
&
, here's a solution for the alignment with=
. It's a user script that is written more for clarity than efficiency (hopefully!), and keep in mind that I'm not at all fluent in QTScript.User Script for Aligning
=
in TeXstudioCreate a new script:
Test bib files
Here are some bib entries to try out on, as I have in my
.gif
.Result:
Notes:
I have yet to figure out how to localize the effect of this user script to a user's selected text, so maybe that will come later if I get around to doing it.Now the script takes into account selected text, and the alignment effect can thus be localized (see gif).Some bugs squished -- the script should be more consistent now. (If there is anyone using this, please try it out and let me know if there are further bugs with this script, thanks.)