Tag Info

Hot answers tagged

28

I ran your code but it appeared to be very slow, I suspect from all the \pgfmathtruncatemacro. But here we can do all calculations with \numexpr easily. This code is based on the TeX primitives \ifnum, \ifcase and \csname..\endcsname. I have used \foreach loops in the first two code samples as I wanted to stay close to your original framework. In the third ...


26

This answer consists of three parts: a solution with manual adjustment of the vertical spacing, a solution with a modified \arraystretch that automatically centers the brackets around the matrix properly (unlike the original \arraystretch!), an explanation of the ugly default spacing. The easy answer You have two issues here: The spacing is ugly ...


26

As @whlt3 said it is required if you intend to have a final horizontal line \hline or a partical line via \cline{...} or if you want to have some extra space blow that line produced via the optional argument of \\. If not then it is completely optional. I would however suggest to use \\ on all lines as that allows you to easily add or reorder rows in your ...


22

It's been a while since I played with NumPy, but I used to call the numpy.savetxt function to export my data as a .csv format: import numpy A = numpy.random.randn(4,4) numpy.savetxt("mydata.csv", A) The sample file mydata.csv was generated accordingly: 1.058690791897618361e-01 4.236767150069661314e-01 -9.871862191240249329e-02 1.896410657805123634e+00 ...


22

The most straightforward way of putting something in a framed box is the \fbox command. \documentclass{article} \begin{document} \newcommand{\sep}{\hspace*{.5em}} \noindent $\fbox{5} \sep \fbox{2} \sep \fbox{7} \sep \fbox{-5} \sep \fbox{16} \sep \fbox{12}$ \end{document} Now that does not look very nice, the boxes are differently sized, depending ...


20

You can stick some \struts in there (the height+depth of a paren): \documentclass{article} \usepackage{mathtools} \begin{document} \[ \begin{bmatrix} \dfrac{\strut\partial f}{\strut\partial x} \\ \dfrac{\strut\partial f}{\strut\partial y} \end{bmatrix} \] \end{document}


19

Just for fun (but perhaps it can be useful to anyone), there is my Lua solution: Main TeX file \documentclass{article} \usepackage{pgffor} \usepackage{xcolor} \usepackage{courier} % Courier has bold series, while cm doesnt \usepackage[active,tightpage]{preview}\PreviewEnvironment{tabular} % Load lua program, and define macros for accessing its functions ...


17

The blkarray package allows to do complex border matrix with relatively simple code: \documentclass{article} \usepackage{blkarray} \usepackage{multirow} \begin{document} \[ \begin{blockarray}{cc|cccc|cccc} & 1\dots 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 \\ \begin{block}{c(c|cccc|cccc@{\hspace*{5pt}})} ...


16

Here is a sans-tikz approach to typesetting an array. The etoolbox package provides \docsvlist that processes a comma separated value (CSV) list using the element-wise generic \do command that takes one argument. By redefining \do, you can modify the operation performed on/to each element. In the following minimal working example, the ...


16

To answer the specific question you are asking, here is a complete minimal example. \documentclass{standalone} \usepackage{pgfmath} \begin{document} \def\names{{"Katie","Frank","Laura","Joe"}}% \pgfmathparse{\names[2]}\pgfmathresult \end{document} So, you need to use the pgfmath parser to do the job through \pgfmathparse and then use the result of the ...


16

I have modified the sudoku.sty for you and here are the contents of the 4x4 sudoku44.sty file. Save the contents below in the name sudoku44.sty and keep it in the same directory as your .tex file. (Alternatively put the file in C:\Program Files\MiKTeX 2.9\tex\latex\sudoku\ and run a refresh file name data base if on windows.) %% %% This is file ...


16

You don't need to modify sudoku.sty, just to use its infrastructure: we can use the macros as modified by Harish Kumar, but changing their names. In this way you can input both sudoku and shidoku puzzles using a similar syntax. \documentclass{article} \usepackage{sudoku} \makeatletter \newcommand*\@shidoku@grid{ \linethickness{\sudokuthinline}% ...


16

After getting these two answers I'd like to publish my solution also. After seeing jfbu's answer I was a bit intimidated and I went the luatex way. The code is probably not efficient, but it can produce an animated PDF – unfortunately this feature only works in Adobe Reader – or pages with the different evolution phases. Also this code only works with n×n ...


15

Working from [SciPy-User] 2d array to Latex: $ python Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> a=numpy.zeros((2,2)) >>> print " \\\\\n".join([" & ".join(map(str,line)) for line in a]) 0.0 & 0.0 \\ 0.0 & 0.0 >>> Add on tabular, table, ...


14

\documentclass{article} \usepackage{amsmath} \begin{document} % ... \[\arraycolsep=1.4pt\def\arraystretch{2.2} \begin{array}{ccccc} x(1) & = & \dfrac{x(0)}{1} & = & x(0)\\ x(2) & = & \dfrac{x(1)}{2} & = & \dfrac{x(0)}{2}\\ x(3) & = & \dfrac{x(2)}{3} & = & \dfrac{x(0)}{2.3}\\ x(4) & = & \dfrac{x(3)}{4} ...


13

\documentclass{article} \usepackage{array} \newcount\tc \makeatletter \def\x@multispan#1{% \begingroup \@multicnt#1\relax \def\xtmp{}% \let\sp@n\relax \loop\ifnum\@multicnt>\@ne \xdef\xtmp{\xtmp\span\omit}\advance\@multicnt\m@ne\repeat \endgroup \xtmp} \protected\def\>#1{% \ifnum#1>\numexpr\tc+\@ne\relax ...


13

You can use a simple tabular and colortbl: \documentclass{article} \usepackage{colortbl} \usepackage{amsmath,amssymb} \begin{document} \begin{tabular}{c@{\,}l@{}} & $p$ \\ \arrayrulecolor{blue} & $p \to q$ \\\cline{2-2} $\therefore$ & $q$ \\ \end{tabular} \end{document} You can change the color of ...


13

Here's a possible solution using a tabular: \documentclass{article} \usepackage{array} \newcolumntype{P}{% >{\rule[-0.6cm]{0pt}{1.5cm}\centering$}p{1cm}<{$}} \begin{document} \noindent\begin{tabular}{!{\vrule width 2pt}P|P!{\vrule width 2pt}P|P!{\vrule width 2pt}} \noalign{\hrule height 2pt} a & b & c & d \tabularnewline \hline a & ...


13

This answer may be more generic than specifically relating to TikZ/PGF. (La)TeX is a macro-based language, so it does not work as expected compared to other languages when dealing with "arrays". For example, while \names[2] should yield Laura where \def\names{Katie, Frank, Laura, Joe} (indexing from 0), (La)TeX considers [2] to have no connection to ...


13

In the cvs version of pgf/tikz or in the version available for texlive at tlcontrib there is an experimental undocumented dim function in pgfmath defined as \makeatletter % dim function: return dimension of an array % dim({1,2,3}) return 3 % dim({{1,2,3},{4,5,6}}) return 2 \pgfmathdeclarefunction{dim}{1}{% \begingroup \pgfmath@count=0\relax ...


12

Basic Example: Here is an example of one way to reproduce the Division Algorithm from Page 4 of Grobner Bases and their Applications by Kaitlyn Moran using an array. Notes: multirow was used to center the \sqrt{xy^2 + 1} term in between the two rows. \multicolumn{1}{c}{<text>} was used to center content within a cell Extended Example For the ...


12

Here's a solution which (a) uses the align* environment instead of the array environment and (b) inverts the order of the arguments inside the cases environment (as I believe that this may be closer to general usage of this environment). It also defines a macro called \abs to simplify typesetting in the body of the example. \documentclass{article} ...


12

The spacing is all wrong if you use an array, the AMS alignments provide alignment whilst preserving operator spacing: \documentclass{article} \usepackage{amsmath} \begin{document} \begin{equation} \begin{array}{ccl} a + b + c & = & d \\ e + f & = & g \\ h & = & i \end{array} \end{equation} ...


12

The mathtools provides a \vdotswithin command exactly for this situation: \documentclass{article} \usepackage{mathtools} \begin{document} \begin{align} 0 &= \text{some equation} \\ 0 &= \text{some other equation} \\ &\vdotswithin{=} \notag \\ 0 &= \text{last equation} \end{align} \end{document}


12

A possibility using TikZ and matrix of math nodes (from the matrix library) to build the natrices; the braces for the dimensions were built using a brace decoration from the decorations.pathreplacing library: \documentclass{article} \usepackage{tikz} \usepackage{geometry} \usetikzlibrary{matrix,positioning,decorations.pathreplacing} \begin{document} ...


11

You can move the lines further apart by specifying arraystretch: \documentclass[a4paper,10pt]{article} \usepackage{arydshln} \setlength{\dashlinegap}{2pt} \begin{document} \[ \Gamma = \left({\renewcommand*{\arraystretch}{1.5} \begin{array}{c:c} \Gamma_{A} & \Gamma_{AB} \\ \hdashline (\Gamma_{AB})^\top & \Gamma_{B} ...


11

The manual of memoir says that emulated package can be "disemulated", so the instructions \documentclass{memoir} \DisemulatePackage{array} \usepackage{array} should do the job (I omit options and other packages just for the sake of brevity). However, it doesn't seem to work for array, because some errors are raised about already defined things, for ...


11

The array package allows for inserting tokens at the start of cells: \documentclass{article} \usepackage{array} \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} \begin{document} $ \def\mycolor{} \newcolumntype{R}{>{\mycolor}r} \newcolumntype{C}{>{\mycolor}c} \newcolumntype{L}{>{\mycolor}l} ...


11

Is it a nomenclature? Then you can use nomentbl package for this. A MWE \documentclass{article} \usepackage[intoc]{nomentbl} \makenomenclature \renewcommand{\nomname}{List of Abbreviations and Symbols} \renewcommand{\nompreamble}{Following symbols are used in the present work:} \setlength{\nomitemsep}{-\parsep} \usepackage[colorlinks=true]{hyperref} ...


11

You could use the glossaries package; a little example: \documentclass{article} \usepackage{glossaries} \newglossary{symbols}{sym}{sbl}{List of Abbreviations and Symbols} \makeglossary \newglossaryentry{fn}{type=symbols,name={\ensuremath{F_n}},sort=fn, description={Empirical (sample) distribution function}} ...



Only top voted, non community-wiki answers of a minimum length are eligible