3

I saw on the Internet a lecture with the title 8 QUEENS PROBLEM USING BACK TRACKING. There is a drawing of the Board following. How to make this using the Latex? (I tried using the package Chessboard, but the result is very different)

\documentclass{article}
\usepackage{chessboard}
\storechessboardstyle{8x8}{maxfield=d8}
\begin{document}
\chessboard[style=4x4,setwhite={Qd4}, pgfstyle=straightmove,
arrow=to,linewidth=0.2ex,
color=red,
pgfstyle=straightmove,
markmoves={d4-h8,d4-a7,d4-a1,d4-g1,d4-d8,d4-d1,d4-a4,d4-h4},
shortenstart=1ex,showmover=false]
\end{document}

enter image description here

3
  • 1
    Use xskake instead. It's more flexible
    – skpblack
    Sep 3, 2014 at 21:32
  • 3
    Please think carefully about the titles you use for question. 'How to make this using the Latex?' could be anything: something like 'How do I show the queens problem using the chessboard package?' would be much better.
    – Joseph Wright
    Sep 4, 2014 at 5:56
  • @skpblack: xskak and chessboard do different things and xskak actually loads and uses chessboard to print boards. Sep 4, 2014 at 13:37

1 Answer 1

7

Maybe a start:

\documentclass{standalone}
\usepackage[LSB,LSBC3,T1]{fontenc}
\usepackage{chessboard}
\storechessboardstyle{8x8}{%
  maxfield=h8,
  borderwidth=10mm,
  boardfontencoding=LSBC3,
  color=white,
  colorwhitebackfields,
  color=black,
  colorblackbackfields,
  blackfieldmaskcolor=black,
  whitepiececolor=yellow,
  whitepiecemaskcolor=red,
  addfontcolors,
  pgfstyle=border,
  color=white,
  markregion=a1-h8,
  }
\begin{document}
  \chessboard[
    style=8x8,
    setwhite={Qa8,Qb4,Qc1,Qd3,Qe6,Qf2,Qg7,Qh5},
    pgfstyle=straightmove,
    arrow=stealth,
    linewidth=.5ex,
    padding=1ex,
    color=blue!75!white,
    pgfstyle=straightmove,
    shortenstart=1ex,
    showmover=true,
    markmoves={d3-h7,d3-a6,d3-b1,d3-f1,d3-d8,d3-d1,d3-a3,d3-h3},
  ]
\end{document}

fancier chess board

For straighter arrows:

\documentclass{standalone}
\usepackage[LSB,LSBC3,T1]{fontenc}
\usepackage{chessboard}
\usetikzlibrary{arrows.meta}
\makeatletter
\cbDefinePgfMoveStyle{mystraightmove}{%
    \pgfsetlinewidth{\board@pgf@linewidth}%
    \setlength\len@board@tempx{\dimexpr 0.1em + \board@pgf@shortenstart \relax}%
    \pgfsetshortenstart{\len@board@tempx}%
    \setlength\len@board@tempx{\board@pgf@shortenend}%
    \pgfsetshortenend{\len@board@tempx}%
    \pgfsetarrowsend{\board@pgf@arrow}%
    \pgfsetrectcap
    \pgfpathmoveto{\pgfpointorigin}%
    \pgfpathlineto{\pgfpointanchor{#1}{center}}%
    \pgfusepath{stroke}}%
\makeatother
\storechessboardstyle{8x8}{%
  maxfield=h8,
  borderwidth=10mm,
  boardfontencoding=LSBC3,
  color=white,
  colorwhitebackfields,
  color=black,
  colorblackbackfields,
  blackfieldmaskcolor=black,
  whitepiececolor=yellow,
  whitepiecemaskcolor=red,
  addfontcolors,
  pgfstyle=border,
  color=white,
  markregion=a1-h8,
  }
\begin{document}
  \chessboard[
    style=8x8,
    setwhite={Qa8,Qb4,Qc1,Qd3,Qe6,Qf2,Qg7,Qh5},
    pgfstyle=mystraightmove,
    linewidth=.5ex,
    padding=1ex,
    color=blue!75!white,
    arrow={Triangle[width=1.5ex, length=1ex]},
    shortenstart=1ex,
    shortenend=-.5ex,
    showmover=false,
    markmoves={d3-h7,d3-a6,d3-b1,d3-f1,d3-d8,d3-d1,d3-a3,d3-h3},
  ]
\end{document}

straighter arrows

I tried to figure out a way to wrap the arrows in a pgf transparency group so that I could make them partially transparent without weirdness. However, when I tried this, the arrows disappeared altogether and I couldn't figure it out.

2
  • You can switch the opacity before markmoves and then back again: E.g. opacity=0.5, markmoves={d3-h7,d3-a6,d3-b1}, opacity=1, markmoves={d3-f1,d3-d8,d3-d1,d3-a3,d3-h3}, Sep 4, 2014 at 13:43
  • @UlrikeFischer Thanks. There is no issue making the arrows partially transparent per se. However, I wanted to wrap them in a transparency group to avoid showing the way they are constructed. That is, if I just set the opacity to .5, say, then you can see where the line is made and how it crosses the arrow head. So I tried to use a transparency group so they would look uniform. I tried to put this in the definition of mystraightmove but I must have done it wrongly as the arrows disappeared completely when I did that.
    – cfr
    Sep 4, 2014 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.